changeset 13539:a4b5cad8f7c6

Added command line parser class.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 26 Jul 2011 21:21:23 +0200
parents ac64163efbe8
children 0dbf8681cd08
files gui/octave-gui.pro gui/src/CommandLineParser.cpp gui/src/CommandLineParser.h gui/src/FilesDockWidget.cpp gui/src/OctaveGUI.cpp gui/src/ResourceManager.cpp gui/src/ResourceManager.h
diffstat 7 files changed, 155 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gui/octave-gui.pro	Tue Jul 26 19:14:06 2011 +0200
+++ b/gui/octave-gui.pro	Tue Jul 26 21:21:23 2011 +0200
@@ -85,7 +85,8 @@
     src/qirc/IClientSocket.cpp \
     src/SettingsDialog.cpp \
     src/OctaveGUI.cpp \
-    src/ResourceManager.cpp
+    src/ResourceManager.cpp \
+    src/CommandLineParser.cpp
 
 HEADERS += \
         src/terminal/TerminalCharacterDecoder.h \
@@ -128,7 +129,8 @@
     src/qirc/IRCClient.h \
     src/qirc/IClientSocket.h \
     src/SettingsDialog.h \
-    src/ResourceManager.h
+    src/ResourceManager.h \
+    src/CommandLineParser.h
 
 FORMS += \
     src/SettingsDialog.ui
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/src/CommandLineParser.cpp	Tue Jul 26 21:21:23 2011 +0200
@@ -0,0 +1,47 @@
+/* OctaveGUI - A graphical user interface for Octave
+ * Copyright (C) 2011 Jacob Dawid
+ * jacob.dawid@googlemail.com
+ *
+ * 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 3 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.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CommandLineParser.h"
+
+CommandLineParser::CommandLineParser ()
+{
+}
+
+void
+CommandLineParser::registerOption (CommandLineOption commandLineOption)
+{
+  if (m_registeredCommandLineOptions.contains(commandLineOption))
+    m_registeredCommandLineOptions.append(commandLineOption);
+}
+
+void
+CommandLineParser::registerOption (QString longOption, QString shortOption, QString description, bool withArgument)
+{
+  CommandLineOption commandLineOption;
+  commandLineOption.longOption = longOption;
+  commandLineOption.shortOption = shortOption;
+  commandLineOption.description = description;
+  commandLineOption.withArgument = withArgument;
+  registerOption (commandLineOption);
+}
+
+void
+CommandLineParser::parse (int argc, char** argv)
+{
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/src/CommandLineParser.h	Tue Jul 26 21:21:23 2011 +0200
@@ -0,0 +1,51 @@
+/* OctaveGUI - A graphical user interface for Octave
+ * Copyright (C) 2011 Jacob Dawid
+ * jacob.dawid@googlemail.com
+ *
+ * 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 3 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.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMMANDLINEPARSER_H
+#define COMMANDLINEPARSER_H
+
+#include <QList>
+#include <QString>
+
+class CommandLineParser
+{
+public:
+  struct CommandLineOption
+  {
+    QString longOption;
+    QString shortOption;
+    QString description;
+    bool withArgument;
+
+    bool operator== (CommandLineOption other)
+    {
+        return longOption == other.longOption
+            || shortOption == other.shortOption;
+    }
+  };
+
+  CommandLineParser ();
+  void registerOption (CommandLineOption commandLineOption);
+  void registerOption (QString longOption, QString shortOption, QString description, bool withArgument);
+  void parse (int argc, char** argv);
+
+private:
+  QList<CommandLineOption> m_registeredCommandLineOptions;
+};
+
+#endif // COMMANDLINEPARSER_H
--- a/gui/src/FilesDockWidget.cpp	Tue Jul 26 19:14:06 2011 +0200
+++ b/gui/src/FilesDockWidget.cpp	Tue Jul 26 21:21:23 2011 +0200
@@ -24,6 +24,7 @@
 #include <QCompleter>
 #include <QSettings>
 #include <QProcess>
+#include <QDebug>
 
 FilesDockWidget::FilesDockWidget (QWidget * parent):QDockWidget (parent)
 {
@@ -172,4 +173,5 @@
   m_fileTreeView->setColumnHidden (3, !settings->value ("showLastModified").toBool ());
   m_fileTreeView->setAlternatingRowColors (settings->value ("useAlternatingRowColors").toBool ());
   //if (settings.value ("showHiddenFiles").toBool ())
+  // TODO: React on option for hidden files.
 }
--- a/gui/src/OctaveGUI.cpp	Tue Jul 26 19:14:06 2011 +0200
+++ b/gui/src/OctaveGUI.cpp	Tue Jul 26 21:21:23 2011 +0200
@@ -19,6 +19,7 @@
 #include <QtGui/QApplication>
 #include <QTranslator>
 #include <QSettings>
+#include "CommandLineParser.h"
 #include "ResourceManager.h"
 #include "MainWindow.h"
 
@@ -26,6 +27,10 @@
 main (int argc, char *argv[])
 {
   QApplication application (argc, argv);
+  CommandLineParser commandLineParser;
+  commandLineParser.registerOption ("--config", "-c", "Tells OctaveGUI to use that configuration file.", true);
+  commandLineParser.parse (argc, argv);
+
   // QSettings *settings = ResourceManager::instance ()->instance ();
 
   // TODO: reimplement translation.
--- a/gui/src/ResourceManager.cpp	Tue Jul 26 19:14:06 2011 +0200
+++ b/gui/src/ResourceManager.cpp	Tue Jul 26 21:21:23 2011 +0200
@@ -1,12 +1,31 @@
+/* OctaveGUI - A graphical user interface for Octave
+ * Copyright (C) 2011 Jacob Dawid
+ * jacob.dawid@googlemail.com
+ *
+ * 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 3 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.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "ResourceManager.h"
 
 ResourceManager ResourceManager::m_singleton;
 
 ResourceManager::ResourceManager ()
 {
+  m_settings = 0;
   QDesktopServices desktopServices;
   m_homePath = desktopServices.storageLocation (QDesktopServices::HomeLocation);
-  m_settings = new QSettings (m_homePath + "/.octave-gui", QSettings::IniFormat);
+  setSettings(m_homePath + "/.octave-gui");
 }
 
 ResourceManager::~ResourceManager ()
@@ -25,3 +44,10 @@
 {
   return m_homePath;
 }
+
+void
+ResourceManager::setSettings (QString file)
+{
+  delete m_settings;
+  m_settings = new QSettings (file, QSettings::IniFormat);
+}
--- a/gui/src/ResourceManager.h	Tue Jul 26 19:14:06 2011 +0200
+++ b/gui/src/ResourceManager.h	Tue Jul 26 21:21:23 2011 +0200
@@ -1,3 +1,21 @@
+/* OctaveGUI - A graphical user interface for Octave
+ * Copyright (C) 2011 Jacob Dawid
+ * jacob.dawid@googlemail.com
+ *
+ * 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 3 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.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef RESOURCEMANAGER_H
 #define RESOURCEMANAGER_H
 
@@ -17,6 +35,7 @@
 
   QSettings *settings ();
   QString homePath ();
+  void setSettings (QString file);
 private:
   ResourceManager ();