Skip to content

Commit

Permalink
MainWindow: Moved FileDialog to own subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w committed Jan 24, 2014
1 parent f073c6d commit 0bbfd90
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 45 deletions.
40 changes: 40 additions & 0 deletions include/FileDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* FileDialog.h - declaration of class FileDialog
*
* Copyright (c) 2014 Lukas W <lukaswhl/at/gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/


#ifndef FILEDIALOG_H
#define FILEDIALOG_H

#include <QtGui/QFileDialog>

class FileDialog : public QFileDialog
{
Q_OBJECT
public:
explicit FileDialog( QWidget *parent = 0, const QString &caption = QString(),
const QString &directory = QString(),
const QString &filter = QString() );
};

#endif // FILEDIALOG_HPP
2 changes: 0 additions & 2 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class QAction;
class QDomElement;
class QGridLayout;
class QMdiArea;
class QFileDialog;

class configManager;
class PluginView;
Expand Down Expand Up @@ -100,7 +99,6 @@ public slots:
}
void createNewProject( void );
void createNewProjectFromTemplate( QAction * _idx );
QFileDialog* newFileDialog( const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString() );
void openProject( void );
bool saveProject( void );
bool saveProjectAs( void );
Expand Down
59 changes: 16 additions & 43 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@


#include <QtXml/QDomElement>
#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtGui/QApplication>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopServices>
#include <QtGui/QFileDialog>
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QMenuBar>
Expand Down Expand Up @@ -63,6 +61,7 @@
#include "ProjectJournal.h"
#include "AutomationEditor.h"
#include "templates.h"
#include "FileDialog.h"



Expand Down Expand Up @@ -682,47 +681,23 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx )



QFileDialog* MainWindow::newFileDialog( const QString& caption, const QString& directory, const QString& filter )
{
QFileDialog* fd = new QFileDialog( this, caption, directory, filter);
#if QT_VERSION >= 0x040806
fd->setOption( QFileDialog::DontUseCustomDirectoryIcons );
#endif

QList<QUrl> urls = fd->sidebarUrls();
urls << QUrl::fromLocalFile( QDesktopServices::storageLocation( QDesktopServices::DesktopLocation ) );
// Find downloads directory
QDir downloadDir( QDir::homePath() + "/Downloads" );
if (! downloadDir.exists())
downloadDir = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation ) + "/Downloads";
if (downloadDir.exists())
urls << QUrl::fromLocalFile( downloadDir.absolutePath() );
fd->setSidebarUrls(urls);

return fd;
}




void MainWindow::openProject( void )
{
if( mayChangeProject() )
{
QFileDialog* ofd = newFileDialog( tr( "Open project" ), "",
FileDialog ofd( this, tr( "Open project" ), "",
tr( "MultiMedia Project (*.mmp *.mmpz *.xml)" ) );

ofd->setDirectory( configManager::inst()->userProjectsDir() );
ofd->setFileMode( QFileDialog::ExistingFiles );
if( ofd->exec () == QDialog::Accepted &&
!ofd->selectedFiles().isEmpty() )
ofd.setDirectory( configManager::inst()->userProjectsDir() );
ofd.setFileMode( QFileDialog::ExistingFiles );
if( ofd.exec () == QDialog::Accepted &&
!ofd.selectedFiles().isEmpty() )
{
setCursor( Qt::WaitCursor );
engine::getSong()->loadProject(
ofd->selectedFiles()[0] );
ofd.selectedFiles()[0] );
setCursor( Qt::ArrowCursor );
}
delete ofd;
}
}

Expand Down Expand Up @@ -773,31 +748,29 @@ bool MainWindow::saveProject( void )

bool MainWindow::saveProjectAs( void )
{
QFileDialog* sfd = newFileDialog( tr( "Save project" ), "",
FileDialog sfd( this, tr( "Save project" ), "",
tr( "MultiMedia Project (*.mmp *.mmpz);;"
"MultiMedia Project Template (*.mpt)" ) );
sfd->setAcceptMode( QFileDialog::AcceptSave );
sfd->setFileMode( QFileDialog::AnyFile );
sfd.setAcceptMode( QFileDialog::AcceptSave );
sfd.setFileMode( QFileDialog::AnyFile );
QString f = engine::getSong()->projectFileName();
if( f != "" )
{
sfd->setDirectory( QFileInfo( f ).absolutePath() );
sfd->selectFile( QFileInfo( f ).fileName() );
sfd.setDirectory( QFileInfo( f ).absolutePath() );
sfd.selectFile( QFileInfo( f ).fileName() );
}
else
{
sfd->setDirectory( configManager::inst()->userProjectsDir() );
sfd.setDirectory( configManager::inst()->userProjectsDir() );
}

if( sfd->exec () == QFileDialog::Accepted &&
!sfd->selectedFiles().isEmpty() && sfd->selectedFiles()[0] != "" )
if( sfd.exec () == QFileDialog::Accepted &&
!sfd.selectedFiles().isEmpty() && sfd.selectedFiles()[0] != "" )
{
engine::getSong()->guiSaveProjectAs(
sfd->selectedFiles()[0] );
delete sfd;
sfd.selectedFiles()[0] );
return( TRUE );
}
delete sfd;
return( FALSE );
}

Expand Down
57 changes: 57 additions & 0 deletions src/gui/dialogs/FileDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* FileDialog.cpp - implementation of class FileDialog
*
* Copyright (c) 2014 Lukas W <lukaswhl/at/gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/


#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtGui/QDesktopServices>

#include "FileDialog.h"





FileDialog::FileDialog( QWidget *parent, const QString &caption,
const QString &directory, const QString &filter ) :
QFileDialog( parent, caption, directory, filter )
{
#if QT_VERSION >= 0x040806
setOption( QFileDialog::DontUseCustomDirectoryIcons );
#endif

// Add additional locations to the sidebar
QList<QUrl> urls = sidebarUrls();
urls << QUrl::fromLocalFile( QDesktopServices::storageLocation( QDesktopServices::DesktopLocation ) );
// Find downloads directory
QDir downloadDir( QDir::homePath() + "/Downloads" );
if ( ! downloadDir.exists() )
downloadDir = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation ) + "/Downloads";
if ( downloadDir.exists() )
urls << QUrl::fromLocalFile( downloadDir.absolutePath() );
setSidebarUrls(urls);
}


#include "moc_FileDialog.cxx"

0 comments on commit 0bbfd90

Please sign in to comment.