From 0bbfd907aec3235f31aad494b16d450d2b2fee4b Mon Sep 17 00:00:00 2001 From: Lukas W Date: Wed, 22 Jan 2014 22:10:52 +0100 Subject: [PATCH] MainWindow: Moved FileDialog to own subclass --- include/FileDialog.h | 40 +++++++++++++++++++++++ include/MainWindow.h | 2 -- src/gui/MainWindow.cpp | 59 +++++++++------------------------- src/gui/dialogs/FileDialog.cpp | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 45 deletions(-) create mode 100644 include/FileDialog.h create mode 100644 src/gui/dialogs/FileDialog.cpp diff --git a/include/FileDialog.h b/include/FileDialog.h new file mode 100644 index 000000000..4a0c678ce --- /dev/null +++ b/include/FileDialog.h @@ -0,0 +1,40 @@ +/* + * FileDialog.h - declaration of class FileDialog + * + * Copyright (c) 2014 Lukas W + * + * 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 + +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 diff --git a/include/MainWindow.h b/include/MainWindow.h index ae71003b8..6335c6401 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -36,7 +36,6 @@ class QAction; class QDomElement; class QGridLayout; class QMdiArea; -class QFileDialog; class configManager; class PluginView; @@ -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 ); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 211f76620..d23d9b5a5 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -24,12 +24,10 @@ #include -#include #include #include #include #include -#include #include #include #include @@ -63,6 +61,7 @@ #include "ProjectJournal.h" #include "AutomationEditor.h" #include "templates.h" +#include "FileDialog.h" @@ -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 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; } } @@ -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 ); } diff --git a/src/gui/dialogs/FileDialog.cpp b/src/gui/dialogs/FileDialog.cpp new file mode 100644 index 000000000..d506a8209 --- /dev/null +++ b/src/gui/dialogs/FileDialog.cpp @@ -0,0 +1,57 @@ +/* + * FileDialog.cpp - implementation of class FileDialog + * + * Copyright (c) 2014 Lukas W + * + * 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 +#include +#include + +#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 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"