summaryrefslogtreecommitdiff
path: root/muse2/muse/widgets/projectcreateimpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/muse/widgets/projectcreateimpl.cpp')
-rw-r--r--muse2/muse/widgets/projectcreateimpl.cpp191
1 files changed, 170 insertions, 21 deletions
diff --git a/muse2/muse/widgets/projectcreateimpl.cpp b/muse2/muse/widgets/projectcreateimpl.cpp
index 31973101..665d725e 100644
--- a/muse2/muse/widgets/projectcreateimpl.cpp
+++ b/muse2/muse/widgets/projectcreateimpl.cpp
@@ -4,6 +4,7 @@
// $Id: ./muse/widgets/projectcreateimpl.cpp $
//
// Copyright (C) 1999-2011 by Werner Schweer and others
+// (C) Copyright 2011 Tim E. Real (terminator356 on sourceforge)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -21,12 +22,16 @@
//
//=========================================================
#include <stdio.h>
-#include <qfiledialog.h>
-#include <qdir.h>
+#include <QFileDialog>
+#include <QDir>
+#include <QStringList>
+
#include "projectcreateimpl.h"
#include "gconfig.h"
#include "globals.h"
#include "app.h"
+#include "helper.h"
+#include "icons.h"
namespace MusEGui {
@@ -35,10 +40,51 @@ ProjectCreateImpl::ProjectCreateImpl(QWidget *parent) :
{
setupUi(this);
- createFolderCheckbox->setChecked(MusEGlobal::config.projectStoreInFolder);
+ //bool is_new = (MusEGlobal::museProject == MusEGlobal::museProjectInitPath);
+ directoryPath = MusEGlobal::config.projectBaseFolder;
+
+ QStringList filters = localizedStringListFromCharArray(MusEGlobal::project_create_file_save_pattern, "file_patterns");
+ projectFileTypeCB->addItems(filters);
+
+ QString proj_title = MusEGlobal::muse->projectTitle();
+ QString proj_path = MusEGlobal::muse->projectPath();
+ QString proj_ext = MusEGlobal::muse->projectExtension();
+
+ projectNameEdit->setText(proj_title);
+
+ bool is_template = proj_path.startsWith(MusEGlobal::configPath + "/templates");
+
+ templateCheckBox->setChecked(is_template);
+
+ projDirPath = proj_path;
+
+ int type_idx = 0;
+ if(!proj_ext.isEmpty())
+ {
+ // FIXME Imperfect. Trying to avoid adding yet another series of character strings. p4.0.40
+ type_idx = projectFileTypeCB->findText(proj_ext, Qt::MatchContains | Qt::MatchCaseSensitive);
+ if(type_idx == -1)
+ type_idx = 0;
+ }
+ projectFileTypeCB->setCurrentIndex(type_idx);
+
+ projDirToolButton->setIcon(*openIcon);
+ browseDirButton->setIcon(*openIcon);
+ restorePathButton->setIcon(*undoIcon);
+
+ restorePathButton->setEnabled(false); // Disabled at first.
+
+ //createFolderCheckbox->setChecked(MusEGlobal::config.projectStoreInFolder && is_new); // Suggest no folder if not new.
+
+ connect(templateCheckBox,SIGNAL(clicked()), this, SLOT(templateButtonChanged()));
+ //connect(templateCheckBox,SIGNAL(clicked()), this, SLOT(updateDirectoryPath()));
+ connect(projDirToolButton,SIGNAL(clicked()), this, SLOT(browseProjDir()));
+ connect(restorePathButton,SIGNAL(clicked()), this, SLOT(restorePath()));
connect(browseDirButton,SIGNAL(clicked()), this, SLOT(selectDirectory()));
- connect(projectNameEdit,SIGNAL(textChanged(QString)), this, SLOT(updateDirectoryPath()));
- connect(createFolderCheckbox,SIGNAL(clicked()), this, SLOT(updateDirectoryPath()));
+ //connect(projectNameEdit,SIGNAL(textChanged(QString)), this, SLOT(updateDirectoryPath()));
+ connect(projectNameEdit,SIGNAL(textChanged(QString)), this, SLOT(updateProjectName()));
+ connect(createFolderCheckbox,SIGNAL(clicked()), this, SLOT(createProjFolderChanged()));
+ connect(projectFileTypeCB,SIGNAL(currentIndexChanged(int)), this, SLOT(updateDirectoryPath()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
#if QT_VERSION >= 0x040700
projectNameEdit->setPlaceholderText("<Project Name>");
@@ -46,52 +92,155 @@ ProjectCreateImpl::ProjectCreateImpl(QWidget *parent) :
// as of Qt-4.7.1
//commentEdit->setPlaceholderText("<Add information about project here>");
#endif
- directoryPath = MusEGlobal::config.projectBaseFolder;
updateDirectoryPath();
show();
}
void ProjectCreateImpl::selectDirectory()
{
- QFileDialog qfd;
- qfd.selectFile(directoryPath);
- qfd.setFileMode(QFileDialog::DirectoryOnly);
- if (qfd.exec() == QDialog::Rejected) {
- return;
- }
- directoryPath=qfd.selectedFiles().first();
+ QString dpath = templateCheckBox->isChecked() ?
+ (overrideTemplDirPath.isEmpty() ? (MusEGlobal::configPath + QString("/templates")) : overrideTemplDirPath) :
+ (overrideDirPath.isEmpty() ? directoryPath : overrideDirPath);
+
+ QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory"), dpath);
+ if(dir.isEmpty())
+ return;
+
+ (templateCheckBox->isChecked() ? overrideTemplDirPath : overrideDirPath) = dir;
+ restorePathButton->setEnabled(true);
updateDirectoryPath();
}
-void ProjectCreateImpl::updateDirectoryPath()
+void ProjectCreateImpl::updateProjectName()
{
+ QString curExt = projectFileTypeCB->currentText();
+ if(curExt.isEmpty())
+ curExt = ".med";
+ else
+ {
+ curExt = MusEGui::getFilterExtension(curExt);
+ // Do we have a valid extension?
+ if(curExt.isEmpty())
+ curExt = ".med";
+ }
+
QString name = "";
if (createFolderCheckbox->isChecked()) {
if (!projectNameEdit->text().isEmpty())
- name = projectNameEdit->text() + "/" + projectNameEdit->text() + ".med";
+ //name = projectNameEdit->text() + "/" + projectNameEdit->text() + ".med";
+ name = projectNameEdit->text() + "/" + projectNameEdit->text() + curExt;
//storageDirEdit->setText(directoryPath + name );
} else {
if (!projectNameEdit->text().isEmpty())
- name = projectNameEdit->text() + ".med";
+ //name = projectNameEdit->text() + ".med";
+ name = projectNameEdit->text() + curExt;
//storageDirEdit->setText(directoryPath +"/" + name);
}
- storageDirEdit->setText(directoryPath +"/" + name ); // Tim
+
+ bool is_new = (MusEGlobal::museProject == MusEGlobal::museProjectInitPath);
+
+ QString dpath = templateCheckBox->isChecked() ?
+ (overrideTemplDirPath.isEmpty() ? (MusEGlobal::configPath + QString("/templates")) : overrideTemplDirPath) :
+ (overrideDirPath.isEmpty() ? (is_new ? directoryPath : projDirPath) : overrideDirPath);
+
+ QDir proj_dir(dpath);
+ //if(is_project && MusEGlobal::config.projectStoreInFolder)
+ bool is_project = dpath.startsWith(MusEGlobal::config.projectBaseFolder);
+ //bool is_template = dpath.startsWith(MusEGlobal::configPath + "/templates") && templateCheckBox->isChecked();
+ //bool is_new = (MusEGlobal::museProject == MusEGlobal::museProjectInitPath) && MusEGlobal::config.projectStoreInFolder;
+ //bool is_new = (MusEGlobal::museProject == MusEGlobal::museProjectInitPath) &&
+ MusEGlobal::config.projectStoreInFolder &&
+ (templateCheckBox->isChecked() ? overrideTemplDirPath.isEmpty() : overrideDirPath.isEmpty());
+ //bool is_template = is_new && dpath.startsWith(MusEGlobal::configPath + "/templates") && templateCheckBox->isChecked();
+ if(!is_new && createFolderCheckbox->isChecked() && !templateCheckBox->isChecked() &&
+ (templateCheckBox->isChecked() ? overrideTemplDirPath.isEmpty() : overrideDirPath.isEmpty()))
+ proj_dir.cdUp();
+ dpath = proj_dir.absolutePath();
+
+ //if(!initProjPath.isEmpty())
+ //{
+ // initProjPath.clear();
+ //}
+
+ storageDirEdit->blockSignals(true);
+ storageDirEdit->setText(dpath + "/" + name );
+ storageDirEdit->blockSignals(false);
+
+ projDirLineEdit->setEnabled(!templateCheckBox->isChecked() && is_project);
+}
+
+void ProjectCreateImpl::updateDirectoryPath()
+{
+ updateProjectName();
+
+ projDirLineEdit->blockSignals(true);
+ projDirLineEdit->setText(MusEGlobal::config.projectBaseFolder);
+ projDirLineEdit->blockSignals(false);
}
-QString ProjectCreateImpl::getProjectPath()
+QString ProjectCreateImpl::getProjectPath() const
{
return storageDirEdit->text();
}
-QString ProjectCreateImpl::getSongInfo()
+
+QString ProjectCreateImpl::getSongInfo() const
{
return commentEdit->toPlainText();
}
+
void ProjectCreateImpl::ok()
{
MusEGlobal::config.projectStoreInFolder = createFolderCheckbox->isChecked();
- MusEGlobal::config.projectBaseFolder = directoryPath;
- MusEGlobal::muse->changeConfig(true);
+ //MusEGlobal::config.projectBaseFolder = directoryPath;
+ //MusEGlobal::muse->changeConfig(true);
emit accept();
}
+void ProjectCreateImpl::createProjFolderChanged()
+{
+ //MusEGlobal::config.projectStoreInFolder = createFolderCheckbox->isChecked();
+ //MusEGlobal::muse->changeConfig(true); // Save to config file.
+ updateDirectoryPath();
+}
+
+void ProjectCreateImpl::browseProjDir()
+{
+ QString dir = MusEGui::browseProjectFolder(this);
+ if(!dir.isEmpty())
+ {
+ directoryPath = dir;
+ MusEGlobal::config.projectBaseFolder = dir;
+ MusEGlobal::muse->changeConfig(true); // Save to config file.
+ updateDirectoryPath();
+ }
+}
+
+void ProjectCreateImpl::templateButtonChanged()
+{
+ restorePathButton->setEnabled(templateCheckBox->isChecked() ? !overrideTemplDirPath.isEmpty() : !overrideDirPath.isEmpty());
+ updateDirectoryPath();
+}
+
+void ProjectCreateImpl::restorePath()
+{
+ if(templateCheckBox->isChecked())
+ overrideTemplDirPath.clear();
+ else
+ overrideDirPath.clear();
+ restorePathButton->setEnabled(templateCheckBox->isChecked() ? !overrideTemplDirPath.isEmpty() : !overrideDirPath.isEmpty());
+ updateDirectoryPath();
+}
+
+/*
+bool ProjectCreateImpl::getProjectIsTemplate() const
+{
+ return templateCheckBox->isChecked();
+}
+
+QString ProjectCreateImpl::getTemplatePath() const
+{
+ return templDirPath;
+}
+*/
+
} //namespace MusEGui