Commit ecc1331c authored by Adam Goins's avatar Adam Goins
Browse files

Modified QView to accept a preference file via command line. Fixes #814

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@8276 41f8697f-d340-4b68-9986-7bafba869bb8
parent 4d4efa73
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -196,7 +196,12 @@ int main(int argc, char *argv[]) {
  for (int i = 1; i < argc; i++) {
    if (i != newWindow) {
      try {
        vw->workspace()->addCubeViewport(QString(argv[i]));
        QString arg(argv[i]);
        if (arg.startsWith("-pref")) {
            i++;
            continue;
        }
        vw->workspace()->addCubeViewport(arg);
        openingAFileSucceeded = true;
      }
      catch (IException &e) {
+27 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <locale.h>

#include <QDesktopServices>
#include <QFileInfo>
#include <QObject>
#include <QMessageBox>
#include <QUrl>
@@ -13,6 +14,7 @@
#endif

#include "FileName.h"
#include "Preference.h"
#include "IException.h"
#include "IString.h"

@@ -22,11 +24,36 @@ namespace Isis {
   *
   * @param argc Pass this in from main(argc, argv)
   * @param argv Pass this in from main(argc, argv)
   * 
   * @internal
   * @history 2017-10-06 Adam Goins - QIsisApplication now checks for a "-pref" flag 
   *                        in the command-line arguments and loads the following 
   *                        preference file if it exists. Fixes # 814
   */
  QIsisApplication::QIsisApplication(int &argc, char *argv[]) :
    QApplication(argc, argv) {
    // try to use US locale for numbers so we don't end up printing "," instead
    //   of "." where it might count.
        
    
    for (int i = 1; i < argc; i++) {
        QString arg(argv[i]);
        if (arg.startsWith("-pref")) {
            
            // So that we can grab the file located after the current '-pref' flag.
            int nextIndex = i + 1;
            
            if (nextIndex < argc) {
                FileName preferenceFile(argv[nextIndex]);
                QString filePath = preferenceFile.expanded();
                Preference::Preferences().clear();
                Preference::Preferences().Load(filePath);
            }
            else {
                QMessageBox::warning(NULL, "Warning", "Preference flag set but no preference file given.");
            }
        }
    } 
    setlocale(LC_NUMERIC, "en_US");

    QDesktopServices::setUrlHandler("http", this, "openUrl");