view libgui/src/resource-manager.h @ 25103:078b795c5219 stable

maint: style check C++ ahead of 4.4 release. * ButtonGroup.cc, Canvas.cc, Figure.cc, GLCanvas.cc, GLCanvas.h, ListBoxControl.cc, ObjectProxy.cc, QTerminal.h, dialog.cc, documentation.cc, files-dock-widget.cc, history-dock-widget.cc, file-editor-tab.cc, file-editor.h, find-dialog.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h, main-window.cc, webinfo.cc, resource-manager.h, settings-dialog.cc, shortcut-manager.cc, shortcut-manager.h, variable-editor.cc, workspace-view.cc, build-env.in.cc, __ilu__.cc, cellfun.cc, data.cc, dirfns.cc, dynamic-ld.h, environment.cc, error.cc, fcn-info.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, help.cc, interpreter.cc, load-path.cc, load-save.cc, ls-mat5.cc, mex.cc, oct-stream.cc, oct-stream.h, qz.cc, sighandlers.cc, sparse-xpow.cc, svd.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, url-handle-manager.h, utils.cc, variables.cc, __init_fltk__.cc, __ode15__.cc, gzip.cc, ov-base.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-java.cc, ov-re-diag.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, bp-table.cc, comment-list.h, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, lex.h, parse.h, pt-binop.h, pt-decl.h, pt-eval.cc, pt-jit.cc, pt-jit.h, pt-misc.h, token.h, CMatrix.cc, CMatrix.h, CSparse.cc, CSparse.h, dMatrix.h, fCMatrix.cc, fCMatrix.h, fMatrix.h, Faddeeva.cc, gepbalance.cc, hess.cc, oct-fftw.cc, oct-fftw.h, file-stat.cc, lo-sysinfo.cc, action-container.h, f77-fcn.h, lo-regexp.cc, oct-mutex.h, oct-shlib.cc: Use Octave coding conventions in C++ files.
author Rik <rik@octave.org>
date Tue, 03 Apr 2018 13:52:07 -0700
parents 6652d3823428
children ba8227df92ae
line wrap: on
line source

/*

Copyright (C) 2011-2018 Jacob Dawid

This file is part of Octave.

Octave 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.

Octave 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 Octave; see the file COPYING.  If not, see
<https://www.gnu.org/licenses/>.

*/

#if ! defined (octave_resource_manager_h)
#define octave_resource_manager_h 1

#include <QDesktopServices>
#include <QIcon>
#include <QComboBox>
#include <QMap>
#include <QSettings>
#include <QTranslator>

namespace octave
{
  class resource_manager : public QObject
  {
    Q_OBJECT

  protected:

  public:

    resource_manager (void);

    // No copying!

    resource_manager (const resource_manager&) = delete;

    resource_manager& operator = (const resource_manager&) = delete;

    ~resource_manager ();

    static QSettings * get_settings (void)
    {
      return instance_ok () ? instance->do_get_settings () : nullptr;
    }

    static QIcon icon (const QString& icon_name, bool fallback = true)
    {
      if (instance_ok ())
        return instance->do_icon (icon_name, fallback);

      return QIcon ();
    }

    static QSettings * get_default_settings (void)
    {
      return instance_ok () ? instance->do_get_default_settings () : nullptr;
    }

    static QString get_settings_file (void)
    {
      return instance_ok () ? instance->do_get_settings_file () : QString ();
    }

    static void reload_settings (void)
    {
      if (instance_ok ())
        instance->do_reload_settings ();
    }

    static void set_settings (const QString& file)
    {
      if (instance_ok ())
        instance->do_set_settings (file);
    }

    static bool update_settings_key (const QString& new_key,
                                     const QString& old_key)
    {
      return (instance_ok ()
              ? instance->do_update_settings_key (new_key, old_key)
              : false);
    }

    static void combo_encoding (QComboBox *combo, QString current = QString ())
    {
      if (instance_ok ())
        instance->do_combo_encoding (combo, current);
    }

    static QString get_gui_translation_dir (void);

    static void config_translators (QTranslator*, QTranslator*, QTranslator*);

    static void update_network_settings (void)
    {
      if (instance_ok ())
        instance->do_update_network_settings ();
    }

    static bool is_first_run (void)
    {
      return instance_ok () ? instance->do_is_first_run () : true;
    }

    static QString storage_class_chars (void) { return "afghip"; }
    static QStringList storage_class_names (void);
    static QList<QColor> storage_class_default_colors (void);

    static QString terminal_color_chars (void) { return "fbsc"; }
    static QStringList terminal_color_names (void);
    static QList<QColor> terminal_default_colors (void);

    static resource_manager *instance;

  public slots:

    static void cleanup_instance (void) { delete instance; instance = nullptr; }

    static QString varedit_color_chars (void) {return "fbsha"; }
    static QStringList varedit_color_names (void);
    static QList<QColor> varedit_default_colors (void);

  private:

    static bool instance_ok (void);

    QSettings * do_get_settings (void) const;

    QSettings * do_get_default_settings (void) const;

    QString do_get_settings_directory (void);

    QString do_get_settings_file (void);

    void do_reload_settings (void);

    void do_set_settings (const QString& file);

    bool do_update_settings_key (const QString& new_key, const QString& old_key);

    bool do_is_first_run (void) const;

    void do_update_network_settings (void);

    QIcon do_icon (const QString& icon, bool fallback);

    void do_combo_encoding (QComboBox *combo, QString current);

    QString m_settings_directory;

    QString m_settings_file;

    QSettings *m_settings;

    QSettings *m_default_settings;
  };
}

// FIXME: This is temporary and should be removed when all classes that
// use the resource_manager class are also inside the octave namespace.
using octave::resource_manager;

#endif