add a manually updated version number.
[mussa.git] / qui / MussaWindow.cpp
index 09cdef5093b76bc884e5599cc03758f10de3b3fc..2ab6299d925ac36226d56a69593b6bb13c8005e9 100644 (file)
@@ -1,6 +1,7 @@
 #include "py/python.hpp"
 #include "qui/MussaWindow.hpp"
 #include "mussa_exceptions.hpp"
+#include "version.hpp"
 
 #include <QAction>
 #include <QApplication>
@@ -24,6 +25,7 @@
 
 #include <boost/filesystem/path.hpp>
 #include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/convenience.hpp>
 namespace fs = boost::filesystem;
 #include <boost/bind.hpp>
 
@@ -32,11 +34,11 @@ using namespace std;
 MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) :
   QMainWindow(parent),
   analysis(analysis_),
-  default_dir(QDir::home().absolutePath().toStdString(), fs::native),
+  default_dir(new QDir(QDir::home().absolutePath())),
   motif_editor(0),
   setup_analysis_dialog(new MussaSetupDialog(this)),
   subanalysis_window(new SubanalysisWindow(analysis)),
-  browser(new SequenceBrowserWidget(this)),  
+  browser(new SequenceBrowserWidget(default_dir, this)),  
   mussaViewTB(new QToolBar("Path Views")),
   zoom(new ZoomWidget),
   threshold(new ThresholdWidget),
@@ -270,7 +272,7 @@ void MussaWindow::setupMainMenu()
 
 void MussaWindow::setupAssistant()
 {
-#if defined(QT_ASSISTANT_FOUND)
+#if defined(QT_QTASSISTANT_FOUND)
   QStringList manualAssistantArgs;
   manualAssistantArgs = QStringList();
   manualAssistantArgs << "-profile" << "./doc/manual/mussagl_manual.adp";
@@ -283,14 +285,17 @@ void MussaWindow::setupAssistant()
   
 void MussaWindow::about()
 {
-  QString msg("Welcome to Multiple Species Sequence Analysis\n"
-              "(c) 2005-2006 California Institute of Technology\n"
-              "Tristan De Buysscher, Diane Trout\n");
-   msg += "\n\r";
-   msg += "OpenGL: ";
-   msg += (char *)glGetString(GL_VERSION);
-   msg += "\n";
-   QMessageBox::about(this, tr("About mussa"), msg);
+  QString msg;
+  msg += "Welcome to Multiple Species Sequence Analysis\n";
+  msg += "(c) 2005-2006 California Institute of Technology\n";
+  msg += "Diane Trout, Tristan De Buysscher, Brandon King\n";
+  msg += "Version: ";
+  msg += mussa_version;
+  msg += "\n";
+  msg += "OpenGL: ";
+  msg += (char *)glGetString(GL_VERSION);
+  msg += "\n";
+  QMessageBox::about(this, tr("About mussa"), msg);
 }
 
 void MussaWindow::clear()
@@ -354,7 +359,7 @@ void MussaWindow::saveAnalysisAs()
   std::auto_ptr<QFileDialog> dialog(new QFileDialog(this));
   dialog->setAcceptMode(QFileDialog::AcceptSave);
   dialog->setFileMode(QFileDialog::AnyFile);
-  dialog->setDirectory(QDir(default_dir.native_directory_string().c_str()));
+  dialog->setDirectory(*default_dir);
 
   QStringList fileNames;
   if (not dialog->exec()) {
@@ -380,7 +385,8 @@ void MussaWindow::saveAnalysisAs()
     return;
   }
   analysis->save(save_path);
-  default_dir = (save_path / "..").normalize();
+  fs::path normalized_path = (save_path / "..").normalize();   
+  default_dir->setPath(normalized_path.native_directory_string().c_str());
 }
 
 bool MussaWindow::isClearingAnalysisSafe()
@@ -426,12 +432,11 @@ void MussaWindow::editMotifs()
 
 void MussaWindow::loadMotifList()
 {
-  QString caption("Load a motif list");
+  QString caption("Mussa Load Motifs");
   QString filter("Motif list(*.txt *.mtl)");
-  QDir default_qdir(default_dir.native_directory_string().c_str());
   QString path = QFileDialog::getOpenFileName(this,
                                               caption, 
-                                              default_qdir.absolutePath(),
+                                              default_dir->absolutePath(),
                                               filter);
   // user hit cancel?
   if (path.isNull()) 
@@ -440,33 +445,53 @@ void MussaWindow::loadMotifList()
   try {
     fs::path converted_path(path.toStdString(), fs::native);
     analysis->load_motifs(converted_path);
-    default_dir = converted_path.branch_path();
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
     emit changedMotifs();
   } catch (runtime_error e) {
     QString msg("Unable to load ");
     msg += path;
     msg += "\n";
     msg += e.what();
-    QMessageBox::warning(this, "Load Motifs", msg);
+    QMessageBox::warning(this, caption, msg);
   }
-  assert (analysis != 0);
 }
 
 void MussaWindow::saveMotifList()
 {
-  NotImplementedBox();
-}
+  QString caption("Mussa Save Motifs");
+  QString filter("Motif list(*.txt *.mtl)");
+  QString path = QFileDialog::getSaveFileName(this,
+                                              caption, 
+                                              default_dir->absolutePath(),
+                                              filter);
+  // user hit cancel?
+  if (path.isNull()) 
+    return;
+  // try to load safely
+  try {
+    fs::path converted_path(path.toStdString(), fs::native);
+    if (fs::extension(converted_path).size() == 0) {
+      // no extension, so add one
+      converted_path = converted_path.string() + ".mtl";
+    }
+    analysis->save_motifs(converted_path);
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
+  } catch (runtime_error e) {
+    QString msg("Unable to save ");
+    msg += path;
+    msg += "\n";
+    msg += e.what();
+    QMessageBox::warning(this, caption, msg);
+  }}
 
 void MussaWindow::loadMupa()
 {
   QString caption("Load a mussa parameter file");
   QString filter("Mussa Parameters (*.mupa)");
-  QDir default_qdir(QDir(default_dir.native_directory_string().c_str()));
-
   QString mupa_path = QFileDialog::getOpenFileName(
                          this,
                          caption, 
-                         default_qdir.absolutePath(),
+                         default_dir->absolutePath(),
                          filter
                       );
   // user hit cancel?
@@ -487,7 +512,7 @@ void MussaWindow::loadMupa()
     setAnalysis(m);
     updateTitle();
     // grab the path ignoring the mupa file portion
-    default_dir = converted_path.branch_path();
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += mupa_path;
@@ -500,12 +525,11 @@ void MussaWindow::loadMupa()
 
 void MussaWindow::loadSavedAnalysis()
 {
-  QDir default_qdir(QDir(default_dir.native_directory_string().c_str()));
   QString caption("Load a previously run analysis");
   QString muway_dir = QFileDialog::getExistingDirectory(
                         this,
                         caption, 
-                        default_qdir.absolutePath()
+                        default_dir->absolutePath()
                      );
   // user hit cancel?
   if (muway_dir.isNull()) 
@@ -526,11 +550,11 @@ void MussaWindow::loadSavedAnalysis()
       // our current window is empty so load and replace.
       setAnalysis(m);
       updateTitle();
-      default_dir = converted_path.branch_path();
+      default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
     } else {
       MussaWindow *win = new MussaWindow(m);
       updateTitle();
-      win->default_dir = converted_path.branch_path();
+      win->default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
       win->show();
     }
   } catch (mussa_load_error e) {
@@ -576,14 +600,29 @@ void MussaWindow::toggleMotifs()
 
 void MussaWindow::showManual()
 {
-#if QT_QTASSISTANT_FOUND
-  manualAssistant->openAssistant();
+#if defined(QT_QTASSISTANT_FOUND)
+  if (manualAssistant) { 
+    manualAssistant->openAssistant();
+  } else {
+    QMessageBox::warning(this,
+                         tr("Mussa Help Error"),
+                         tr("QtAssistant not setup correctly"),
+                         QMessageBox::Ok,
+                         QMessageBox::NoButton,
+                         QMessageBox::NoButton);
+  }
 #else
   try {
     boost::python::object webopen = get_py()["webbrowser.open"];
     webopen("http://woldlab.caltech.edu/~king/mussagl_manual/");
   } catch( boost::python::error_already_set ) {
     PyErr_Print();
+    QMessageBox::warning(this,
+                         tr("Mussa Help Error"),
+                         tr("Unable to launch webbrowser"),
+                         QMessageBox::Ok,
+                         QMessageBox::NoButton,
+                         QMessageBox::NoButton);
   }
 #endif //QT_QTASSISTANT_FOUND
 }
@@ -611,7 +650,7 @@ void MussaWindow::viewMussaAlignment()
                                      "first"));
   } else {
     MussaAlignedWindowRef ma_win( 
-      new MussaAlignedWindow(analysis, selected_paths, subanalysis_window)
+      new MussaAlignedWindow(analysis, default_dir, selected_paths, subanalysis_window)
     );
 
     aligned_windows.push_back(ma_win);