mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-18 19:55:00 -04:00
MainWindow: Moved FileDialog to own subclass
This commit is contained in:
40
include/FileDialog.h
Normal file
40
include/FileDialog.h
Normal file
@@ -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
|
||||
@@ -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 );
|
||||
|
||||
@@ -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>
|
||||
@@ -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<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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
57
src/gui/dialogs/FileDialog.cpp
Normal file
57
src/gui/dialogs/FileDialog.cpp
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user