"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/settings.h" (12 Feb 2021, 4403 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "settings.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef SETTINGS_H
    8 #define SETTINGS_H
    9 
   10 #include "cb2bib_parameters.h"
   11 
   12 #include <QDir>
   13 #include <QSettings>
   14 #include <QStringList>
   15 
   16 class QCoreApplication;
   17 
   18 
   19 class settings : public QSettings
   20 {
   21 
   22     Q_OBJECT
   23 
   24 public:
   25     explicit settings(QObject* parento = 0);
   26     virtual ~settings();
   27 
   28     // Command line data. (Set public for easiest access. Only settings or derived classes should modify it)
   29     QString cl_annote_filename;
   30     QString cl_extract_output_filename;
   31     QString cl_import_filename;
   32     QString cl_index_dirname;
   33     QStringList cl_bibedit_filenames;
   34     QStringList cl_citer_filenames;
   35     QStringList cl_extract_input_filenames;
   36     bool cl_bibedit;
   37     bool cl_cb2bib_import_mode;
   38     bool cl_cb2bib_information;
   39     bool cl_cb2bib_mode;
   40     bool cl_cb2bib_tests;
   41     bool cl_citer;
   42     bool cl_configure;
   43     bool cl_console_mode;
   44     bool cl_doc2bib;
   45     bool cl_html_annote;
   46     bool cl_import;
   47     bool cl_index;
   48     bool cl_sloppy;
   49     bool cl_txt2bib;
   50     bool cl_user_configured;
   51     bool cl_view_annote;
   52 
   53     // Get/Set filenames according to settings
   54     // PdfDirectory is a particular case. If relative, it is relative to the BibTeX file
   55     inline QString fileName(const QString& key) const
   56     {
   57         if (_is_usb_configured_mode)
   58         {
   59             const QString v(value(key).toString());
   60             if (key == "cb2Bib/PdfDirectory")
   61                 if (value("cb2Bib/RelativePdfDirectory").toBool())
   62                     return QDir::toNativeSeparators(QDir::cleanPath(v));
   63             if (key.endsWith("Bin")) // Pathless binary to be found on PATH
   64                 if (!(v.contains('/') || v.contains('\\')))
   65                     return v;
   66             return QDir::toNativeSeparators(QDir::cleanPath(_c2bAppDir.absoluteFilePath(v)));
   67         }
   68         else
   69             return QDir::toNativeSeparators(QDir::cleanPath(value(key).toString()));
   70     }
   71     inline void setFilename(const QString& key, const QString& fn)
   72     {
   73         if (_is_usb_configured_mode)
   74         {
   75             if (key == "cb2Bib/PdfDirectory")
   76             {
   77                 if (value("cb2Bib/RelativePdfDirectory").toBool())
   78                 {
   79                     setValue(key, fn);
   80                     return;
   81                 }
   82             }
   83             setValue(key, _c2bAppDir.relativeFilePath(fn));
   84         }
   85         else
   86             setValue(key, fn);
   87     }
   88 
   89     inline bool loaded() const
   90     {
   91         return _is_loaded;
   92     }
   93     inline bool isUsbConfiguredMode() const
   94     {
   95         return _is_usb_configured_mode;
   96     }
   97     inline QStringList confCommandFlags() const
   98     {
   99         return _conf_command_flags;
  100     }
  101     inline QString tempPath() const
  102     {
  103         return _tmp_dir_path;
  104     }
  105     inline QString applicationPid() const
  106     {
  107         return _application_pid;
  108     }
  109     void setDefaultValue(const QString& key, const QVariant& defaulValue);
  110     QString applicationDataDir() const;
  111 
  112     static bool isConsoleMode(const int argc, char** argv);
  113     static bool isSingleApplicationMode(const int argc, char** argv);
  114     static settings* instance()
  115     {
  116         Q_ASSERT_X(_c2b_global_settings, "settings", "settings was not instantiated");
  117         return _c2b_global_settings;
  118     }
  119 
  120 
  121 protected:
  122     settings(const QString& organization, const QString& application, QObject* parento = 0);
  123     explicit settings(const QString& fn, QObject* parento = 0);
  124     // init() has a virtual method, keep it out of the constructor
  125     void init(bool command_line = true);
  126 
  127     static bool isConfiguredMode();
  128     static const QString configuredFilename();
  129     virtual QString decodeFilename(const QString& fn) const;
  130 
  131 
  132 private:
  133     QCoreApplication* _c2bApp;
  134     QDir _c2bAppDir;
  135     QString _application_pid;
  136     QString _tmp_dir_path;
  137     QStringList _conf_command_flags;
  138     bool _is_loaded;
  139     bool _is_usb_configured_mode;
  140     static settings* _c2b_global_settings;
  141     void _init();
  142     void checkCommand(bool* action, int* actions);
  143     void printUsage();
  144     void readCommandLine();
  145     void setDefaults();
  146 };
  147 
  148 #endif