1 //===========================================
2 // Lumina-DE source code
3 // Copyright (c) 2016, Ken Moore
4 // Available under the 3-clause BSD license
5 // See the LICENSE file for full details
6 //===========================================
7 #include "page_theme.h"
8 #include "ui_page_theme.h"
9
10 #include "../ColorDialog.h"
11 #include "../ThemeDialog.h"
12 //==========
13 // PUBLIC
14 //==========
page_theme(QWidget * parent)15 page_theme::page_theme(QWidget *parent) : PageWidget(parent), ui(new Ui::page_theme()){
16 ui->setupUi(this);
17 findQt5Themes();
18 loading = false;
19 PINFO = new LPlugins(); //load the info class
20 connect(ui->spin_session_fontsize, SIGNAL(valueChanged(int)), this, SLOT(settingsChanged()) );
21 connect(ui->combo_session_themefile, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
22 connect(ui->combo_session_colorfile, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
23 connect(ui->combo_session_icontheme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
24 connect(ui->font_session_theme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
25 connect(ui->tool_session_newcolor, SIGNAL(clicked()), this, SLOT(sessionEditColor()) );
26 connect(ui->tool_session_newtheme, SIGNAL(clicked()), this, SLOT(sessionEditTheme()) );
27 connect(ui->combo_session_cursortheme, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged()) );
28 connect(ui->combo_qt5_theme, SIGNAL(currentIndexChanged(int)), this, SLOT(checkQt5Theme()) );
29 updateIcons();
30 }
31
~page_theme()32 page_theme::~page_theme(){
33
34 }
35
36 //================
37 // PUBLIC SLOTS
38 //================
SaveSettings()39 void page_theme::SaveSettings(){
40 QString themefile = ui->combo_session_themefile->itemData( ui->combo_session_themefile->currentIndex() ).toString();
41 QString colorfile = ui->combo_session_colorfile->itemData( ui->combo_session_colorfile->currentIndex() ).toString();
42 QString iconset = ui->combo_session_icontheme->currentText();
43 QString font = ui->font_session_theme->currentFont().family();
44 QString fontsize = QString::number(ui->spin_session_fontsize->value())+"pt";
45 QString qt5theme = ui->combo_qt5_theme->currentData().toString();
46 if(qt5theme=="internal_custom"){ qt5theme = ui->line_qt5_custom_theme->text(); }
47 QSettings sessionsettings("lumina-desktop","sessionsettings");
48 sessionsettings.setValue("Qt5_theme_engine", qt5theme);
49
50 //qDebug() << "Saving theme options:" << themefile << colorfile << iconset << font << fontsize;
51 LTHEME::setCurrentSettings( themefile, colorfile, iconset, font, fontsize);
52 LTHEME::setCursorTheme(ui->combo_session_cursortheme->currentText());
53 emit HasPendingChanges(false);
54 }
55
LoadSettings(int)56 void page_theme::LoadSettings(int){
57 emit HasPendingChanges(false);
58 emit ChangePageTitle( tr("Theme Settings") );
59
60 loading = true;
61 //Load the available settings
62 ui->combo_session_cursortheme->clear();
63 ui->combo_session_cursortheme->addItems( LTHEME::availableSystemCursors() );
64
65 ui->combo_session_themefile->clear();
66 ui->combo_session_colorfile->clear();
67 ui->combo_session_icontheme->clear();
68 QStringList current = LTHEME::currentSettings();
69 // - local theme templates
70 QStringList tmp = LTHEME::availableLocalThemes();
71 tmp.sort();
72 for(int i=0; i<tmp.length(); i++){
73 ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
74 if(tmp[i].section("::::",1,1)==current[0]){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
75 }
76 // - system theme templates
77 tmp = LTHEME::availableSystemThemes();
78 tmp.sort();
79 for(int i=0; i<tmp.length(); i++){
80 ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
81 if(tmp[i].section("::::",1,1)==current[0]){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
82 }
83 // - local color schemes
84 tmp = LTHEME::availableLocalColors();
85 tmp.sort();
86 for(int i=0; i<tmp.length(); i++){
87 ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
88 if(tmp[i].section("::::",1,1)==current[1]){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
89 }
90 // - system color schemes
91 tmp = LTHEME::availableSystemColors();
92 tmp.sort();
93 for(int i=0; i<tmp.length(); i++){
94 ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
95 if(tmp[i].section("::::",1,1)==current[1]){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
96 }
97 // - icon themes
98 tmp = LTHEME::availableSystemIcons();
99 tmp.sort();
100 for(int i=0; i<tmp.length(); i++){
101 ui->combo_session_icontheme->addItem(tmp[i]);
102 if(tmp[i]==current[2]){ ui->combo_session_icontheme->setCurrentIndex(i); }
103 }
104 // - Font
105 ui->font_session_theme->setCurrentFont( QFont(current[3]) );
106 // - Font Size
107 ui->spin_session_fontsize->setValue( current[4].section("p",0,0).toInt() );
108
109 int cur = ui->combo_session_cursortheme->findText( LTHEME::currentCursor() );
110 if(cur>=0){ ui->combo_session_cursortheme->setCurrentIndex(cur); }
111
112 QSettings sessionsettings("lumina-desktop","sessionsettings");
113 QString qt5theme = sessionsettings.value("Qt5_theme_engine", "lthemeengine").toString();
114 int index = ui->combo_qt5_theme->findData(qt5theme);
115 if(index <0){
116 ui->line_qt5_custom_theme->setText(qt5theme);
117 index = ui->combo_qt5_theme->findData("internal_custom");
118 }
119 if(index>=0){ ui->combo_qt5_theme->setCurrentIndex(index); }
120 checkQt5Theme(); //update item visibility
121 QApplication::processEvents();
122 loading = false;
123 }
124
updateIcons()125 void page_theme::updateIcons(){
126 ui->tool_session_newtheme->setIcon( LXDG::findIcon("preferences-desktop-theme","") );
127 ui->tool_session_newcolor->setIcon( LXDG::findIcon("preferences-desktop-color","") );
128 ui->tabWidget->setTabIcon(0, LXDG::findIcon("user-desktop","desktop") );
129 ui->tabWidget->setTabIcon(1, LXDG::findIcon("preferences-system-windows","") );
130 }
131
132 //=================
133 // PRIVATE
134 //=================
findQt5Themes()135 void page_theme::findQt5Themes(){
136 ui->combo_qt5_theme->clear();
137 ui->combo_qt5_theme->addItem( tr("None"), "");
138 ui->combo_qt5_theme->addItem( tr("Manual Setting"), "internal_custom");
139 //Now probe the system and list any themes that are found
140 QStringList paths = QCoreApplication::libraryPaths();
141 qDebug() << "Known Library Paths:" << paths;
142 QStringList engines;
143 for(int i=0; i<paths.length(); i++){
144 if(QFile::exists(paths[i]+"/platformthemes")){
145 QDir dir(paths[i]+"/platformthemes");
146 QStringList libs = dir.entryList(QStringList("lib*.so*"), QDir::Files, QDir::NoSort) ;
147 for(int j=0; j<libs.length(); j++){ engines << libs[j].section("lib",1,-1).section(".",0,-2).simplified(); }
148 }
149 }
150 engines.sort();
151 for(int i=0; i<engines.length(); i++){
152 if(i==0){ ui->combo_qt5_theme->insertSeparator(2); }
153 ui->combo_qt5_theme->addItem( engines[i], engines[i] );
154 }
155 }
156 //=================
157 // PRIVATE SLOTS
158 //=================
sessionEditColor()159 void page_theme::sessionEditColor(){
160 //Get the current color file
161 QString file = ui->combo_session_colorfile->itemData( ui->combo_session_colorfile->currentIndex() ).toString();
162 //Open the color edit dialog
163 ColorDialog dlg(this, PINFO, file);
164 dlg.exec();
165 //Check whether the file got saved/changed
166 if(dlg.colorname.isEmpty() || dlg.colorpath.isEmpty() ){ return; } //cancelled
167 //Reload the color list and activate the new color
168 // - local color schemes
169 ui->combo_session_colorfile->clear();
170 QStringList tmp = LTHEME::availableLocalColors();
171 tmp.sort();
172 for(int i=0; i<tmp.length(); i++){
173 ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
174 if(tmp[i].section("::::",1,1)==dlg.colorpath){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
175 }
176 // - system color schemes
177 tmp = LTHEME::availableSystemColors();
178 tmp.sort();
179 for(int i=0; i<tmp.length(); i++){
180 ui->combo_session_colorfile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
181 if(tmp[i].section("::::",1,1)==dlg.colorpath){ ui->combo_session_colorfile->setCurrentIndex(ui->combo_session_colorfile->count()-1); }
182 }
183 emit HasPendingChanges(true);
184 }
185
sessionEditTheme()186 void page_theme::sessionEditTheme(){
187 QString file = ui->combo_session_themefile->itemData( ui->combo_session_themefile->currentIndex() ).toString();
188 //Open the theme editor dialog
189 ThemeDialog dlg(this, PINFO, file);
190 dlg.exec();
191 //Check for file change/save
192 if(dlg.themename.isEmpty() || dlg.themepath.isEmpty()){ return; } //cancelled
193 //Reload the theme list and activate the new theme
194 ui->combo_session_themefile->clear();
195 // - local theme templates
196 QStringList tmp = LTHEME::availableLocalThemes();
197 tmp.sort();
198 for(int i=0; i<tmp.length(); i++){
199 ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("Local")+")", tmp[i].section("::::",1,1));
200 if(tmp[i].section("::::",1,1)==dlg.themepath){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
201 }
202 // - system theme templates
203 tmp = LTHEME::availableSystemThemes();
204 tmp.sort();
205 for(int i=0; i<tmp.length(); i++){
206 ui->combo_session_themefile->addItem(tmp[i].section("::::",0,0)+" ("+tr("System")+")", tmp[i].section("::::",1,1));
207 if(tmp[i].section("::::",1,1)==dlg.themepath){ ui->combo_session_themefile->setCurrentIndex(ui->combo_session_themefile->count()-1); }
208 }
209 emit HasPendingChanges(true);
210 }
211
checkQt5Theme()212 void page_theme::checkQt5Theme(){
213 ui->line_qt5_custom_theme->setVisible( ui->combo_qt5_theme->currentData().toString()=="internal_custom");
214 settingsChanged();
215 }
216