Package: krusader / 2:2.5.0-2

ADDED-Reimplementation-of-minimize-to-system-tray-feature.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From: Alexander Bikadorov <bikaejkb@mailbox.tu-berlin.de>
Date: Mon, 4 Jul 2016 16:28:07 +0200
Subject: ADDED: Reimplementation of "minimize to system tray" feature.

Partially reverts commit 8a05cacaf58fba11d6d96b934ce2588a43dc3019.
Using QSystemTrayIcon. Icon is only shown if mainwindow is minimized.
---
 krusader/Konfigurator/kggeneral.cpp |  3 ++-
 krusader/Konfigurator/kgstartup.cpp |  4 +++-
 krusader/defaults.h                 |  4 ++++
 krusader/krusader.cpp               | 47 ++++++++++++++++++++++++++++++++++++-
 krusader/krusader.h                 |  5 ++++
 5 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/krusader/Konfigurator/kggeneral.cpp b/krusader/Konfigurator/kggeneral.cpp
index 3633c93b..07b1780d 100644
--- a/krusader/Konfigurator/kggeneral.cpp
+++ b/krusader/Konfigurator/kggeneral.cpp
@@ -230,8 +230,9 @@ void KgGeneral::createGeneralTab()
 
     KONFIGURATOR_CHECKBOX_PARAM settings[] = { //   cfg_class  cfg_name                default             text                              restart tooltip
         {"Look&Feel", "Warn On Exit",         _WarnOnExit,        i18n("Warn on exit"),           false,  i18n("Display a warning when trying to close the main window.") },    // KDE4: move warn on exit to the other confirmations
+        {"Look&Feel", "Minimize To Tray",     _MinimizeToTray,    i18n("Minimize to tray"),       false,  i18n("The icon will appear in the system tray instead of the taskbar, when Krusader is minimized.") },
     };
-    KonfiguratorCheckBoxGroup *cbs = createCheckBoxGroup(2, 0, settings, 1 /*count*/, generalGrp, PAGE_GENERAL);
+    KonfiguratorCheckBoxGroup *cbs = createCheckBoxGroup(2, 0, settings, 2 /*count*/, generalGrp, PAGE_GENERAL);
     generalGrid->addWidget(cbs, 0, 0);
 
 
diff --git a/krusader/Konfigurator/kgstartup.cpp b/krusader/Konfigurator/kgstartup.cpp
index 4691a4b6..4100bc27 100644
--- a/krusader/Konfigurator/kgstartup.cpp
+++ b/krusader/Konfigurator/kgstartup.cpp
@@ -108,9 +108,11 @@ KgStartup::KgStartup(bool first, QWidget* parent) :
                  "to manually set the main window's size and position at startup.</p>") },
         {"Startup", "Update Default Panel Settings", _RememberPos, i18n("Update default panel settings"), true,
             i18n("When settings of a panel are changed, save them as the default for new panels of the same type.") },
+        {"Startup", "Start To Tray", _StartToTray, i18n("Start to tray"), false,
+            i18n("Krusader starts to tray (if minimize to tray is set), without showing the main window") },
     };
 
-    uiCbGroup = createCheckBoxGroup(2, 0, uiCheckBoxes, 9, uiGrp);
+    uiCbGroup = createCheckBoxGroup(2, 0, uiCheckBoxes, 10, uiGrp);
     connect(uiCbGroup->find("UI Save Settings"), SIGNAL(stateChanged(int)), this, SLOT(slotDisable()));
 
     uiGrid->addWidget(uiCbGroup, 1, 0);
diff --git a/krusader/defaults.h b/krusader/defaults.h
index 8b49ff83..22f94f08 100644
--- a/krusader/defaults.h
+++ b/krusader/defaults.h
@@ -52,6 +52,8 @@
 #define _ShowTerminalEmulator false
 // Remember Position
 #define _RememberPos      true
+// Start to tray
+#define _StartToTray      false
 // Left Tab Bar
 // Right Tab Bar
 // Size where lister is the default viewer
@@ -64,6 +66,8 @@
 #define _FilelistFont   QFontDatabase::systemFont(QFontDatabase::GeneralFont)
 // Warn On Exit ////////
 #define _WarnOnExit     false
+// Minimize To Tray ////
+#define _MinimizeToTray false
 // Mark Dirs ///////////
 #define _MarkDirs       false
 // Show Hidden /////////
diff --git a/krusader/krusader.cpp b/krusader/krusader.cpp
index fea64809..01a4533f 100644
--- a/krusader/krusader.cpp
+++ b/krusader/krusader.cpp
@@ -218,6 +218,20 @@ Krusader::Krusader(const QCommandLineParser &parser) : KParts::MainWindow(0,
     status->setWhatsThis(i18n("Statusbar will show basic information "
                               "about file below mouse pointer."));
 
+    // create tray icon (even if not shown)
+    sysTray = new QSystemTrayIcon(this);
+    sysTray->setIcon(krLoader->loadIcon(privIcon(), KIconLoader::Panel, 22));
+    QMenu *trayMenu = new QMenu(this);
+    trayMenu->addSection(QGuiApplication::applicationDisplayName()); // show "title"
+    QAction *restoreAction = new QAction(i18n("Restore"), this);
+    connect(restoreAction, SIGNAL(triggered()), SLOT(showFromTray()));
+    trayMenu->addAction(restoreAction);
+    trayMenu->addSeparator();
+    trayMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Quit)));
+    sysTray->setContextMenu(trayMenu);
+    // tray is only visible if main window is hidden, so action is always "show"
+    connect(sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(showFromTray()));
+
     setCentralWidget(MAIN_VIEW);
 
     // manage our keyboard short-cuts
@@ -249,7 +263,12 @@ Krusader::Krusader(const QCommandLineParser &parser) : KParts::MainWindow(0,
         }
     }
 
-    show();
+    // view initialized; show window or tray
+    if (gs.readEntry("Start To Tray", _StartToTray)) {
+        sysTray->show();
+    } else {
+        show();
+    }
 
     KrTrashHandler::startWatcher();
     isStarting = false;
@@ -331,6 +350,31 @@ void Krusader::statusBarUpdate(QString& mess)
         statusBar() ->showMessage(mess, 5000);
 }
 
+void Krusader::showFromTray() {
+    setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
+    show();
+    sysTray->hide();
+}
+
+void Krusader::changeEvent(QEvent *event) {
+    QMainWindow::changeEvent(event);
+    if (isExiting)
+        return;
+
+    // toggle tray when minimizing (if enabled)
+    if(event->type() == QEvent::WindowStateChange) {
+        if(isMinimized()) {
+            KConfigGroup group(krConfig, "Look&Feel");
+            if (group.readEntry("Minimize To Tray", _MinimizeToTray)) {
+                sysTray->show();
+                hide();
+            }
+        } else if(isVisible()) {
+            sysTray->hide();
+        }
+    }
+}
+
 void Krusader::moveEvent(QMoveEvent *e) {
     oldPos = e->oldPos();
     KParts::MainWindow::moveEvent(e);
@@ -410,6 +454,7 @@ void Krusader::saveSettings() {
         cfg.writeEntry("Show FN Keys", KrActions::actToggleFnkeys->isChecked());
         cfg.writeEntry("Show Cmd Line", KrActions::actToggleCmdline->isChecked());
         cfg.writeEntry("Show Terminal Emulator", KrActions::actToggleTerminal->isChecked());
+        cfg.writeEntry("Start To Tray", isHidden());
     }
 
     // save popular links
diff --git a/krusader/krusader.h b/krusader/krusader.h
index f1750ae9..e6a444b7 100644
--- a/krusader/krusader.h
+++ b/krusader/krusader.h
@@ -40,6 +40,7 @@
 
 // QtCore
 #include <QCommandLineParser>
+#include <QEvent>
 #include <QStringList>
 #include <QTimer>
 // QtGui
@@ -49,6 +50,7 @@
 #include <QMoveEvent>
 // QtWidgets
 #include <QAction>
+#include <QSystemTrayIcon>
 
 #include <KParts/MainWindow>
 #include <KConfigWidgets/KStandardAction>
@@ -135,11 +137,13 @@ protected slots:
     void doOpenUrl();
     void slotGotNewStartup(const KStartupInfoId &id, const KStartupInfoData &data);
     void slotGotRemoveStartup(const KStartupInfoId &id, const KStartupInfoData &data);
+    void showFromTray();
 
 protected:
     bool queryClose() Q_DECL_OVERRIDE;
     void setupActions();
     bool versionControl();  // handle version differences in krusaderrc
+    void changeEvent(QEvent *even) Q_DECL_OVERRIDE;
     void moveEvent(QMoveEvent *) Q_DECL_OVERRIDE;
     void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
     bool event(QEvent *) Q_DECL_OVERRIDE;
@@ -184,6 +188,7 @@ private:
     ViewActions *_viewActions;
     ListPanelActions *_listPanelActions;
     TabActions *_tabActions;
+    QSystemTrayIcon *sysTray;
     QPoint       oldPos;
     QSize        oldSize;
     bool         isStarting;