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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
//===========================================
// Lumina Desktop Source Code
// Copyright (c) 2016, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "page_interface_panels.h"
#include "ui_page_interface_panels.h"
#include <QInputDialog>
#include "../GetPluginDialog.h"
#include "../AppDialog.h"
//==========
// PUBLIC
//==========
page_interface_panels::page_interface_panels(QWidget *parent) : PageWidget(parent), ui(new Ui::page_interface_panels()){
ui->setupUi(this);
loading = false;
PINFO = new LPlugins();
settings = new QSettings("lumina-desktop","desktopsettings");
connect(ui->tool_panels_add, SIGNAL(clicked()), this, SLOT(newPanel()) );
updateIcons();
//Create panels container
QHBoxLayout *panels_layout = new QHBoxLayout();
panels_layout->setContentsMargins(0,0,0,0);
panels_layout->setAlignment(Qt::AlignLeft);
panels_layout->addStretch();
ui->scroll_panels->widget()->setLayout(panels_layout);
}
page_interface_panels::~page_interface_panels(){
delete PINFO;
}
//================
// PUBLIC SLOTS
//================
void page_interface_panels::SaveSettings(){
QString screenID = QApplication::screens().at(cscreen)->name();
QString DPrefix = "desktop-"+screenID+"/";
settings->setValue(DPrefix+"panels", PANELS.length());
for(int i=0; i<PANELS.length(); i++){
PANELS[i]->SaveSettings(settings);
}
//The plugin ID's will be changed to unique ID's by the desktop - reload in a moment
emit HasPendingChanges(false);
settings->sync(); //save to disk right now
QTimer::singleShot(1000, this, SLOT(LoadSettings()) );
}
void page_interface_panels::LoadSettings(int screennum){
if(screennum>=0){
cscreen = screennum;
}
loading = true;
emit HasPendingChanges(false);
emit ChangePageTitle( tr("Desktop Settings") );
QString screenID = QApplication::screens().at(cscreen)->name();
QString DPrefix = "desktop-"+screenID+"/";
int panelnumber = settings->value(DPrefix+"panels",-1).toInt();
if(panelnumber<0){ panelnumber = 0; }
QHBoxLayout *panels_layout = static_cast<QHBoxLayout*>(ui->scroll_panels->widget()->layout());
//Remove extra panels (if any)
for(int i=panelnumber; i<PANELS.length(); i++){
PanelWidget *tmp = PANELS.takeAt(i);
delete tmp;
i--;
}
int current_count = panels_layout->count()-1;
//Update current panels
for(int i=0; i<current_count; i++) {
PANELS[i]->LoadSettings(settings, cscreen, i);
}
//Create new panels
for(int i=current_count; i<panelnumber; i++){
PanelWidget *tmp = new PanelWidget(ui->scroll_panels->widget(), this, PINFO);
tmp->LoadSettings(settings, cscreen, i);
PANELS << tmp;
connect(tmp, SIGNAL(PanelChanged()), this, SLOT(panelValChanged()) );
connect(tmp, SIGNAL(PanelRemoved(int)), this, SLOT(removePanel(int)) );
panels_layout->insertWidget(panels_layout->count()-1, tmp);
}
QApplication::processEvents();
loading = false;
setupProfiles();
}
void page_interface_panels::updateIcons(){
ui->tool_panels_add->setIcon( LXDG::findIcon("list-add","") );
ui->tool_profile->setIcon( LXDG::findIcon("document-import","") );
}
//=================
// PRIVATE
//=================
void page_interface_panels::setupProfiles(){
//qDebug() << "Start loading profiles";
if(ui->tool_profile->menu()==0){
ui->tool_profile->setMenu( new QMenu(this) );
connect(ui->tool_profile->menu(), SIGNAL(triggered(QAction*)), this, SLOT(applyProfile(QAction*)) );
}
else{ ui->tool_profile->menu()->clear(); }
ui->tool_profile->menu()->addSection("Profiles");
QAction *act = ui->tool_profile->menu()->addAction(tr("No Panels"));
act->setWhatsThis("none");
act = ui->tool_profile->menu()->addAction("Windows");
act->setWhatsThis("windows");
act = ui->tool_profile->menu()->addAction("GNOME2/MATE");
act->setWhatsThis("gnome2");
act = ui->tool_profile->menu()->addAction("XFCE");
act->setWhatsThis("xfce");
act = ui->tool_profile->menu()->addAction("Mac OSX");
act->setWhatsThis("osx");
//Add in any custom profiles
//qDebug() << " - read settings";
QStringList profilesAll = settings->childGroups().filter("panel_");
//qDebug() << " - get current screen";
QString current = QApplication::screens().at(cscreen)->name();
//qDebug() << " - filter list";
for(int i=0; i<profilesAll.length(); i++){
profilesAll[i] = profilesAll[i].section("_",1,-1).section(".",0,-2);
}
//qDebug() << "Found Profiles:" << profilesAll;
profilesAll.removeDuplicates();
profilesAll.removeAll(current);
QStringList profiles = profilesAll.filter("profile_");
for(int p=0; p<2; p++){
if(p==1){ profiles = profilesAll; } //use whats left of the total list
ui->tool_profile->menu()->addSection( p==0 ? tr("Custom Profiles") : tr("Copy Screen") );
for(int i=0; i<profiles.length(); i++){
if(p==0){ profilesAll.removeAll(profiles[i]); } //handling it now
QString title = profiles[i];
if(title.startsWith("profile_")){ title = title.section("profile_",-1); }
QMenu *tmp = new QMenu(ui->tool_profile->menu());
tmp->setTitle(title);
tmp->addAction(LXDG::findIcon("dialog-ok-apply",""), tr("Apply"))->setWhatsThis("profile_apply::::"+profiles[i]);
tmp->addAction(LXDG::findIcon("list-remove",""), tr("Delete"))->setWhatsThis("profile_remove::::"+profiles[i]);
ui->tool_profile->menu()->addMenu(tmp);
}
if(p==0){
//Now add the option to create a new profile
ui->tool_profile->menu()->addAction(LXDG::findIcon("list-add",""), tr("Create Profile"))->setWhatsThis("profile_new");
}
}
}
//=================
// PRIVATE SLOTS
//=================
void page_interface_panels::panelValChanged(){
ui->tool_panels_add->setEnabled(PANELS.length() < 12);
if(!loading){ settingChanged(); }
}
void page_interface_panels::newPanel(){
//if(panelnumber<0){ panelnumber=0; } //just in case
//panelnumber++;
//Now create a new Panel widget with this number
PanelWidget *tmp = new PanelWidget(ui->scroll_panels->widget(), this, PINFO);
tmp->LoadSettings(settings, cscreen, PANELS.length());
PANELS << tmp;
connect(tmp, SIGNAL(PanelChanged()), this, SLOT(panelValChanged()) );
connect(tmp, SIGNAL(PanelRemoved(int)), this, SLOT(removePanel(int)) );
static_cast<QBoxLayout*>(ui->scroll_panels->widget()->layout())->insertWidget(PANELS.length()-1, tmp);
//update the widget first (2 necessary for scroll below to work)
ui->scroll_panels->update();
QApplication::processEvents();
QApplication::processEvents();
ui->scroll_panels->ensureWidgetVisible(tmp);
panelValChanged();
}
void page_interface_panels::removePanel(int pan){
//connected to a signal from the panel widget
bool changed = false;
for(int i=0; i<PANELS.length(); i++){
int num = PANELS[i]->PanelNumber();
if(num==pan){
delete PANELS.takeAt(i);
i--;
changed = true;
}else if(num > pan){
PANELS[i]->ChangePanelNumber(num-1);
changed = true;
}
}
if(!changed){ return; } //nothing done
panelValChanged();
}
void page_interface_panels::applyProfile(QAction *act){
QString wt = act->whatsThis();
if(wt.startsWith("profile_")){
//qDebug() << "Got Profile Action:" << wt;
if(wt=="profile_new"){
bool ok = false;
QString pname = QInputDialog::getText(this, tr("Create Profile"), tr("Name:"), QLineEdit::Normal, "", &ok,Qt::WindowFlags(), Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly );
if(!ok || pname.isEmpty()){ return; } //cancelled
pname = pname.replace(".","_").replace("/","_");
qDebug() << " - Make new profile:" << pname;
pname.prepend("profile_");
settings->setValue("desktop-"+pname+"/panels", PANELS.length());
for(int i=0; i<PANELS.length(); i++){
PANELS[i]->SaveSettings(settings, pname);
}
settings->sync(); //save to disk right now
setupProfiles();
}else if(wt.startsWith("profile_apply::::") ){
applyImport(wt.section("::::",-1) );
}else if(wt.startsWith("profile_remove::::") ){
QString pname = wt.section("::::",-1);
QStringList keys = settings->allKeys().filter(pname);
for(int i=0; i<keys.length(); i++){
if(keys[i].section("/",0,0).contains(pname)){ settings->remove(keys[i]); }
}
setupProfiles();
}
return;
}
//Manually saving settings based on built-in profile
QString screenID = QApplication::screens().at(cscreen)->name();
QString DPrefix = "desktop-"+screenID+"/";
QString PPrefix = "panel_"+screenID+"."; //NEED TO APPEND PANEL NUMBER (0+)
qDebug() << "Apply Profile:" << act->whatsThis() << "To Monitor:" << screenID;
if(act->whatsThis()=="none"){
settings->setValue(DPrefix+"panels", 0); //number of panels
}else if(act->whatsThis()=="windows"){
settings->setValue(DPrefix+"panels", 1); //number of panels
//Panel 1 settings (index 0)
settings->setValue(PPrefix+"0/customColor", false);
settings->setValue(PPrefix+"0/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.04)); //4% of screen height
settings->setValue(PPrefix+"0/hidepanel", false);
settings->setValue(PPrefix+"0/lengthPercent", 100);
settings->setValue(PPrefix+"0/location", "bottom");
settings->setValue(PPrefix+"0/pinLocation", "center");
settings->setValue(PPrefix+"0/pluginlist", QStringList() << "systemstart" << "taskmanager" << "spacer" << "systemtray" << "clock");
}else if(act->whatsThis()=="gnome2"){
settings->setValue(DPrefix+"panels", 2); //number of panels
//Panel 1 settings (index 0)
settings->setValue(PPrefix+"0/customColor", false);
settings->setValue(PPrefix+"0/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.02)); //2% of screen height
settings->setValue(PPrefix+"0/hidepanel", false);
settings->setValue(PPrefix+"0/lengthPercent", 100);
settings->setValue(PPrefix+"0/location", "top");
settings->setValue(PPrefix+"0/pinLocation", "center");
settings->setValue(PPrefix+"0/pluginlist", QStringList() << "appmenu" << "desktopbar" << "spacer" << "systemtray" << "clock" << "systemdashboard");
//Panel 2 settings (index 1)
settings->setValue(PPrefix+"1/customColor", false);
settings->setValue(PPrefix+"1/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.02)); //2% of screen height
settings->setValue(PPrefix+"1/hidepanel", false);
settings->setValue(PPrefix+"1/lengthPercent", 100);
settings->setValue(PPrefix+"1/location", "bottom");
settings->setValue(PPrefix+"1/pinLocation", "center");
settings->setValue(PPrefix+"1/pluginlist", QStringList() << "homebutton" << "taskmanager-nogroups" << "spacer" << "desktopswitcher");
}else if(act->whatsThis()=="xfce"){
settings->setValue(DPrefix+"panels", 2); //number of panels
//Panel 1 settings (index 0)
settings->setValue(PPrefix+"0/customColor", false);
settings->setValue(PPrefix+"0/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.02)); //2% of screen height
settings->setValue(PPrefix+"0/hidepanel", false);
settings->setValue(PPrefix+"0/lengthPercent", 100);
settings->setValue(PPrefix+"0/location", "top");
settings->setValue(PPrefix+"0/pinLocation", "center");
settings->setValue(PPrefix+"0/pluginlist", QStringList() << "appmenu" << "taskmanager-nogroups" << "spacer" << "desktopswitcher" << "clock" << "systemtray" << "systemdashboard");
//Panel 2 settings (index 1)
settings->setValue(PPrefix+"1/customColor", false);
settings->setValue(PPrefix+"1/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.04)); //4% of screen height
settings->setValue(PPrefix+"1/hidepanel", false);
settings->setValue(PPrefix+"1/lengthPercent", 20);
settings->setValue(PPrefix+"1/location", "bottom");
settings->setValue(PPrefix+"1/pinLocation", "center");
settings->setValue(PPrefix+"1/pluginlist", QStringList() << "applauncher::lumina-fm.desktop" << "line"<<"spacer" << "desktopbar" << "spacer" << "line" << "applauncher::lumina-search.desktop");
}else if(act->whatsThis()=="osx"){
settings->setValue(DPrefix+"panels", 2); //number of panels
//Panel 1 settings (index 0)
settings->setValue(PPrefix+"0/customColor", false);
settings->setValue(PPrefix+"0/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.02)); //2% of screen height
settings->setValue(PPrefix+"0/hidepanel", false);
settings->setValue(PPrefix+"0/lengthPercent", 100);
settings->setValue(PPrefix+"0/location", "top");
settings->setValue(PPrefix+"0/pinLocation", "center");
settings->setValue(PPrefix+"0/pluginlist", QStringList() << "systemdashboard" << "spacer" << "systemtray" << "clock" << "applauncher::lumina-search.desktop");
//Panel 2 settings (index 1)
settings->setValue(PPrefix+"1/customColor", false);
settings->setValue(PPrefix+"1/height", qRound(QApplication::screens().at(cscreen)->virtualSize().height()*0.04)); //4% of screen height
settings->setValue(PPrefix+"1/hidepanel", false);
settings->setValue(PPrefix+"1/lengthPercent", 80);
settings->setValue(PPrefix+"1/location", "bottom");
settings->setValue(PPrefix+"1/pinLocation", "center");
settings->setValue(PPrefix+"1/pluginlist", QStringList() << "systemstart" << "applauncher::lumina-fm.desktop" << "desktopbar"<<"spacer" << "line"<< "taskmanager");
}else{
qDebug() << " - unknown profile! ("+act->whatsThis()+")";
return;
}
//Now flush the settings to disk and reload the interface
settings->sync(); //save to disk right now
QTimer::singleShot(1000, this, SLOT(LoadSettings()) );
}
void page_interface_panels::applyImport(QAction *act){
applyImport(act->whatsThis());
}
void page_interface_panels::applyImport(QString fromID){
QString cID = QApplication::screens().at(cscreen)->name();
//QString DPrefix = "desktop-"+screenID+"/";
qDebug() << "Import Panels from " << fromID << " to " << cID;
//First find all the values associated with this ID
int pannum = settings->value("desktop-"+fromID+"/panels").toInt();
QStringList pans = settings->allKeys().filter("panel_"+fromID);
fromID.prepend("panel_");
//save the number of panels which is active
settings->setValue("desktop-"+cID+"/panels", pannum);
//Now move over all the panel settings associated with the fromID
cID.prepend("panel_");
for(int i=0; i<pans.length(); i++){
QString newvar = pans[i];
newvar.replace(fromID, cID);
settings->setValue(newvar, settings->value(pans[i]) );
}
//Now flush the settings to disk and reload the interface
settings->sync(); //save to disk right now
QTimer::singleShot(1000, this, SLOT(LoadSettings()) );
}
|