[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src core/ProjectManager.cpp core/Proje...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src core/ProjectManager.cpp core/Proje... |
Date: |
Tue, 03 Jul 2007 14:17:17 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/07/03 14:17:17
Modified files:
src/core : ProjectManager.cpp ProjectManager.h
src/traverso/dialogs/project: OpenProjectDialog.cpp
OpenProjectDialog.h
src/traverso : Interface.cpp Interface.h
Log message:
different and hopefully robuster way of project renaming detection
outside of the program
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ProjectManager.cpp?cvsroot=traverso&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ProjectManager.h?cvsroot=traverso&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/project/OpenProjectDialog.cpp?cvsroot=traverso&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/project/OpenProjectDialog.h?cvsroot=traverso&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/Interface.cpp?cvsroot=traverso&r1=1.93&r2=1.94
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/Interface.h?cvsroot=traverso&r1=1.38&r2=1.39
Patches:
Index: core/ProjectManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ProjectManager.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- core/ProjectManager.cpp 2 Jul 2007 17:10:07 -0000 1.39
+++ core/ProjectManager.cpp 3 Jul 2007 14:17:16 -0000 1.40
@@ -26,6 +26,7 @@
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
+#include <QFileSystemWatcher>
#include "Project.h"
#include "Song.h"
@@ -35,6 +36,7 @@
#include "Config.h"
#include "FileHelpers.h"
#include <AudioDevice.h>
+#include <Utils.h>
// Always put me below _all_ includes, this is needed
// in case we run with memory leak detection enabled!
@@ -55,11 +57,15 @@
PENTERCONS;
currentProject = (Project*) 0;
m_exitInProgress = false;
- m_renamingDir = false;
+
+ m_watcher = new QFileSystemWatcher(0);
+
+ QString path = config().get_property("Project", "directory",
getenv("HOME")).toString();
+ set_current_project_dir(path);
cpointer().add_contextitem(this);
- connect(&m_resetDirRenamingTimer, SIGNAL(timeout()), this,
SLOT(reset_dir_renaming_progress()));
+ connect(m_watcher, SIGNAL(directoryChanged(const QString&)), this,
SLOT(project_dir_rename_detected(const QString&)));
}
/**
@@ -133,11 +139,10 @@
return 0;
}
- Project* newProject = new Project(projectName);
+ QString newrootdir = config().get_property("Project", "directory",
"/directory/unknown/").toString() + "/" + projectName;
+ m_projectDirs.append(newrootdir);
- // Creating a new dir also emits the dir changed signal
- // so we 'fake' a honored dir renaming here
- dir_rename_started();
+ Project* newProject = new Project(projectName);
if (newProject->create(numSongs, numTracks) < 0) {
delete newProject;
@@ -155,13 +160,11 @@
return 0;
}
+ QString newrootdir = config().get_property("Project", "directory",
"/directory/unknown/").toString() + "/" + projectName;
+ m_projectDirs.append(newrootdir);
Project* newProject = new Project(projectName);
- // Creating a new dir also emits the dir changed signal
- // so we 'fake' a honored dir renaming here
- dir_rename_started();
-
if (newProject->create(0, 0) < 0) {
delete newProject;
info().critical(tr("Unable to create new Project
%1").arg(projectName));
@@ -224,6 +227,9 @@
set_current_project(0);
}
+ QString oldrootdir = config().get_property("Project", "directory",
"/directory/unknown/").toString() + "/" + name;
+ m_projectDirs.removeAll(oldrootdir);
+
return FileHelper::remove_recursively( name );
}
@@ -395,10 +401,11 @@
int ProjectManager::rename_project_dir(const QString & olddir, const QString &
newdir)
{
- dir_rename_started();
-
QDir dir(olddir);
+ m_projectDirs.removeAll(olddir);
+ m_projectDirs.append(newdir);
+
if ( ! dir.rename(olddir, newdir)) {
info().critical(tr("Could not rename Project directory to
%1").arg(newdir));
return - 1;
@@ -407,23 +414,53 @@
return 1;
}
-bool ProjectManager::renaming_directory_in_progress()
+void ProjectManager::set_current_project_dir(const QString & path)
{
- if (m_renamingDir) {
- return true;
+ QDir newdir(path);
+
+ config().set_property("Project", "directory", newdir.canonicalPath());
+
+ QStringList list = newdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ m_projectDirs.clear();
+
+ foreach(QString string, list) {
+ m_projectDirs += path + "/" + string;
}
- return false;
+ m_watcher->addPath(path);
}
-void ProjectManager::reset_dir_renaming_progress()
+void ProjectManager::project_dir_rename_detected(const QString & dirname)
{
- m_renamingDir = false;
+ emit projectDirChangeDetected();
+
+ QString path = config().get_property("Project", "directory",
"").toString();
+ QDir dir(path);
+
+ QStringList list = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+
+ bool startwhining = false;
+ foreach(QString string, list) {
+ if (!m_projectDirs.contains(path + "/" + string)) {
+ startwhining = true;
+ break;
+ }
+ }
+
+
+ if (!startwhining) {
+ return;
+ }
+
+ emit unsupportedProjectDirChangeDetected();
}
-void ProjectManager::dir_rename_started()
+void ProjectManager::add_correct_project_path(const QString & path)
{
- m_renamingDir = true;
- m_resetDirRenamingTimer.start(1000);
+ m_projectDirs.append(path);
}
+void ProjectManager::remove_wrong_project_path(const QString & path)
+{
+ m_projectDirs.removeAll(path);
+}
Index: core/ProjectManager.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ProjectManager.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- core/ProjectManager.h 27 Jun 2007 13:07:17 -0000 1.17
+++ core/ProjectManager.h 3 Jul 2007 14:17:16 -0000 1.18
@@ -26,11 +26,14 @@
#include <QUndoGroup>
#include <QList>
#include <QTimer>
+#include <QStringList>
class Project;
class Song;
class Command;
class ResourcesManager;
+class QFileSystemWatcher;
+
class ProjectManager : public ContextItem
{
@@ -46,12 +49,14 @@
int load_renamed_project(const QString& name);
bool project_exists(const QString& title);
- bool renaming_directory_in_progress();
int remove_project(const QString& title);
void scheduled_for_deletion(Song* song);
void delete_song(Song* song);
+ void set_current_project_dir(const QString& path);
+ void add_correct_project_path(const QString& path);
+ void remove_wrong_project_path(const QString& path);
int rename_project_dir(const QString& olddir, const QString& newdir);
@@ -74,9 +79,9 @@
Project* currentProject;
QList<Song*> m_deletionSongList;
- QTimer m_resetDirRenamingTimer;
bool m_exitInProgress;
- bool m_renamingDir;
+ QStringList m_projectDirs;
+ QFileSystemWatcher* m_watcher;
bool clientRequestInProgress;
static QUndoGroup undogroup;
@@ -84,17 +89,18 @@
void set_current_project(Project* pProject);
bool project_is_current(const QString& title);
- void dir_rename_started();
-
// allow this function to create one instance
friend ProjectManager& pm();
signals:
void projectLoaded(Project* );
void aboutToDelete(Song* );
+ void currentProjectDirChanged();
+ void unsupportedProjectDirChangeDetected();
+ void projectDirChangeDetected();
private slots:
- void reset_dir_renaming_progress();
+ void project_dir_rename_detected(const QString& dirname);
};
Index: traverso/dialogs/project/OpenProjectDialog.cpp
===================================================================
RCS file:
/sources/traverso/traverso/src/traverso/dialogs/project/OpenProjectDialog.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- traverso/dialogs/project/OpenProjectDialog.cpp 26 Jun 2007 18:29:55
-0000 1.10
+++ traverso/dialogs/project/OpenProjectDialog.cpp 3 Jul 2007 14:17:17
-0000 1.11
@@ -29,7 +29,6 @@
#include <QDomDocument>
#include <QFileDialog>
#include <QHeaderView>
-#include <QFileSystemWatcher>
#include <Config.h>
@@ -37,7 +36,6 @@
#include <ProjectManager.h>
#include <Project.h>
#include <Utils.h>
-#include "Interface.h"
// Always put me below _all_ includes, this is needed
// in case we run with memory leak detection enabled!
@@ -48,11 +46,6 @@
{
setupUi(this);
- QString path = config().get_property("Project", "directory",
getenv("HOME")).toString();
- m_watcher = new QFileSystemWatcher(this);
- m_watcher->addPath(path);
- m_dirchangeDetected = false;
-
projectListView->setColumnCount(2);
update_projects_list();
QStringList stringList;
@@ -62,8 +55,9 @@
projectListView->header()->resizeSection(0, 160);
projectListView->header()->resizeSection(1, 30);
+ connect(&pm(), SIGNAL(currentProjectDirChanged()), this,
SLOT(update_projects_list()));
+ connect(&pm(), SIGNAL(projectDirChangeDetected()), this,
SLOT(update_projects_list()));
connect(projectListView, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
this, SLOT(projectitem_clicked(QTreeWidgetItem*,int)));
- connect(m_watcher, SIGNAL(directoryChanged(const QString&)), this,
SLOT(project_dir_rename_detected(const QString&)));
}
OpenProjectDialog::~ OpenProjectDialog( )
@@ -130,6 +124,12 @@
item->setTextAlignment(1, Qt::AlignHCenter);
if (title != dirname) {
+ // Let the ProjectManager know that this path is a
correct one
+ // so it doesn't start whining when the directory is
changed back
+ // to the proper name!
+ pm().add_correct_project_path(path + "/" + title);
+ pm().remove_wrong_project_path(path + "/" + dirname);
+
item->setIcon(0,
style()->standardIcon(QStyle::SP_MessageBoxWarning));
QString html;
html += tr("<p>Project directory name <b>%1</b> is
different from the Project title <b>%2</b>!</p>"
@@ -259,38 +259,7 @@
QMessageBox::information( this, tr("Traverso - Information"),
tr("Created new Project directory for you here: %1\n").arg(newPath), "OK", 0 );
}
- QDir newdir(newPath);
-
- config().set_property("Project", "directory", newdir.canonicalPath());
-
- m_watcher->addPath(newdir.canonicalPath());
-
-
- update_projects_list();
-}
-
-void OpenProjectDialog::project_dir_rename_detected(const QString & dirname)
-{
- update_projects_list();
-
- if (pm().renaming_directory_in_progress()) {
- return;
- }
-
- if (m_dirchangeDetected) {
- return;
- }
-
- m_dirchangeDetected = true;
-
- QMessageBox::critical( Interface::instance(),
- tr("Traverso - Important"),
- tr("A Project directory changed outside of Traverso.
\n\n"
- "This is NOT supported! Please undo this change
now!\n\n"
- "If you want to rename a Project, use the Project
Manager instead!"),
- QMessageBox::Ok);
-
- m_dirchangeDetected = false;
+ pm().set_current_project_dir(newPath);
}
//eof
Index: traverso/dialogs/project/OpenProjectDialog.h
===================================================================
RCS file:
/sources/traverso/traverso/src/traverso/dialogs/project/OpenProjectDialog.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- traverso/dialogs/project/OpenProjectDialog.h 26 Jun 2007 18:07:57
-0000 1.2
+++ traverso/dialogs/project/OpenProjectDialog.h 3 Jul 2007 14:17:17
-0000 1.3
@@ -25,8 +25,6 @@
#include "ui_OpenProjectDialog.h"
#include <QDialog>
-class QFileSystemWatcher;
-
class OpenProjectDialog : public QDialog, protected Ui::OpenProjectDialog
{
Q_OBJECT
@@ -36,17 +34,12 @@
~OpenProjectDialog();
-private:
- QFileSystemWatcher* m_watcher;
- bool m_dirchangeDetected;
-
private slots:
void update_projects_list();
void on_loadProjectButton_clicked();
void on_deleteProjectbutton_clicked();
void on_projectDirSelectButton_clicked();
void projectitem_clicked( QTreeWidgetItem* , int );
- void project_dir_rename_detected(const QString& dirname);
};
#endif
Index: traverso/Interface.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/Interface.cpp,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -b -r1.93 -r1.94
--- traverso/Interface.cpp 26 Jun 2007 18:07:57 -0000 1.93
+++ traverso/Interface.cpp 3 Jul 2007 14:17:17 -0000 1.94
@@ -168,7 +168,7 @@
exportWidget = 0;
m_settingsdialog = 0;
m_projectManagerDialog = 0;
- m_openProjectDialog = new OpenProjectDialog(this);
+ m_openProjectDialog = 0;
m_newProjectDialog = 0;
m_insertSilenceDialog = 0;
m_markerDialog = 0;
@@ -188,6 +188,7 @@
// Connections to core:
connect(&pm(), SIGNAL(projectLoaded(Project*)), this,
SLOT(set_project(Project*)));
connect(&pm(), SIGNAL(aboutToDelete(Song*)), this,
SLOT(delete_songwidget(Song*)));
+ connect(&pm(), SIGNAL(unsupportedProjectDirChangeDetected()), this,
SLOT(project_dir_change_detected()));
cpointer().add_contextitem(this);
@@ -927,6 +928,9 @@
Command* Interface::show_open_project_dialog()
{
+ if (!m_openProjectDialog) {
+ m_openProjectDialog = new OpenProjectDialog(this);
+ }
m_openProjectDialog->show();
return 0;
}
@@ -998,5 +1002,12 @@
QDesktopServices::openUrl(QUrl("http://traverso-daw.org/UserManual"));
}
-// eof
+void Interface::project_dir_change_detected()
+{
+ QMessageBox::critical(this, tr("Traverso - Important"),
+ tr("A Project directory changed outside of
Traverso. \n\n"
+ "This is NOT supported! Please undo this change
now!\n\n"
+ "If you want to rename a Project, use the Project
Manager instead!"),
+ QMessageBox::Ok);
+}
Index: traverso/Interface.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/Interface.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- traverso/Interface.h 7 Jun 2007 04:05:14 -0000 1.38
+++ traverso/Interface.h 3 Jul 2007 14:17:17 -0000 1.39
@@ -168,6 +168,7 @@
private slots:
void delete_songwidget(Song*);
+ void project_dir_change_detected();
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src core/ProjectManager.cpp core/Proje...,
Remon Sijrier <=