Autostart option added
This commit is contained in:
83
src/optionsdialog.h
Normal file
83
src/optionsdialog.h
Normal file
@@ -0,0 +1,83 @@
|
||||
// gKeyMapper - the options window.
|
||||
#ifndef GKEYMAPPER_OPTIONSDIALOG_H
|
||||
#define GKEYMAPPER_OPTIONSDIALOG_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "daemonclient.h"
|
||||
#include "settings.h"
|
||||
|
||||
namespace gkeymapper {
|
||||
|
||||
// Everything the window shows when it opens. The switches come from different
|
||||
// places - the tray is a bus name, autostart is a file, the rest is the GUI's own
|
||||
// config - so they are collected here instead of being passed one by one.
|
||||
struct OptionsState {
|
||||
bool trayAvailable = false;
|
||||
bool autostart = false;
|
||||
GuiSettings settings;
|
||||
DaemonView view;
|
||||
};
|
||||
|
||||
// The options window: the GUI's own switches plus the full daemon status. It is
|
||||
// deliberately not modal - the footer keeps updating while it is open, and a
|
||||
// switch takes effect immediately.
|
||||
class OptionsDialog {
|
||||
public:
|
||||
using ToggleFn = std::function<void(bool)>;
|
||||
// Called with the chosen language code ("" = follow the session).
|
||||
using LanguageFn = std::function<void(const std::string&)>;
|
||||
|
||||
// Creates the window on first use, afterwards it is re-presented.
|
||||
void show(GtkWindow* parent, const OptionsState& state, ToggleFn onTray,
|
||||
ToggleFn onAutostart, LanguageFn onLanguage);
|
||||
|
||||
// While the window is open: keep the status lines in step with the daemon.
|
||||
void update(const DaemonView& view);
|
||||
|
||||
bool is_open() const { return window_ != nullptr; }
|
||||
|
||||
// Closes it, e.g. before the window is rebuilt for another language.
|
||||
void close();
|
||||
|
||||
private:
|
||||
static void on_tray_switch(GObject* object, GParamSpec* spec, gpointer userData);
|
||||
static void on_autostart_switch(GObject* object, GParamSpec* spec, gpointer userData);
|
||||
static void on_language_changed(GObject* object, GParamSpec* spec, gpointer userData);
|
||||
static void on_destroy(GtkWidget* widget, gpointer userData);
|
||||
|
||||
// Fills the widgets from the state the window was last told about.
|
||||
void apply();
|
||||
|
||||
// Everything the window shows, so a status update does not have to carry the
|
||||
// switches along.
|
||||
bool trayAvailable_ = false;
|
||||
bool minimizeToTray_ = false;
|
||||
bool autostart_ = false;
|
||||
std::string language_;
|
||||
DaemonView view_;
|
||||
|
||||
GtkWidget* window_ = nullptr;
|
||||
GtkWidget* traySwitch_ = nullptr;
|
||||
GtkWidget* trayHint_ = nullptr;
|
||||
GtkWidget* autostartSwitch_ = nullptr;
|
||||
GtkWidget* languageDrop_ = nullptr;
|
||||
GtkWidget* trayValue_ = nullptr;
|
||||
GtkWidget* stateValue_ = nullptr;
|
||||
GtkWidget* versionValue_ = nullptr;
|
||||
GtkWidget* deviceValue_ = nullptr;
|
||||
GtkWidget* configValue_ = nullptr;
|
||||
GtkWidget* lastKeyValue_ = nullptr;
|
||||
// Set while the window fills its widgets, so programmatic changes do not look
|
||||
// like the user flipping a switch.
|
||||
bool filling_ = false;
|
||||
ToggleFn onToggled_;
|
||||
ToggleFn onAutostart_;
|
||||
LanguageFn onLanguage_;
|
||||
};
|
||||
|
||||
} // namespace gkeymapper
|
||||
|
||||
#endif // GKEYMAPPER_OPTIONSDIALOG_H
|
||||
Reference in New Issue
Block a user