0 | 0 |
/*
|
1 | 1 |
* Main.vala
|
2 | |
*
|
|
2 |
*
|
3 | 3 |
* Copyright 2013 Tony George <teejee@teejee-pc>
|
4 | |
*
|
|
4 |
*
|
5 | 5 |
* This program is free software; you can redistribute it and/or modify
|
6 | 6 |
* it under the terms of the GNU General Public License as published by
|
7 | 7 |
* the Free Software Foundation; either version 2 of the License, or
|
8 | 8 |
* (at your option) any later version.
|
9 | |
*
|
|
9 |
*
|
10 | 10 |
* This program is distributed in the hope that it will be useful,
|
11 | 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 | 13 |
* GNU General Public License for more details.
|
14 | |
*
|
|
14 |
*
|
15 | 15 |
* You should have received a copy of the GNU General Public License
|
16 | 16 |
* along with this program; if not, write to the Free Software
|
17 | 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 | 18 |
* MA 02110-1301, USA.
|
19 | |
*
|
20 | |
*
|
|
19 |
*
|
|
20 |
*
|
21 | 21 |
*/
|
22 | |
|
|
22 |
|
23 | 23 |
using GLib;
|
24 | 24 |
using Gtk;
|
25 | 25 |
using Gee;
|
|
36 | 36 |
public Main App;
|
37 | 37 |
public const string AppName = "Conky Manager";
|
38 | 38 |
public const string AppShortName = "conky-manager";
|
39 | |
public const string AppVersion = "2.3.3";
|
|
39 |
public const string AppVersion = "2.4";
|
40 | 40 |
public const string AppAuthor = "Tony George";
|
41 | 41 |
public const string AppAuthorEmail = "[email protected]";
|
42 | 42 |
|
|
46 | 46 |
extern void exit(int exit_code);
|
47 | 47 |
|
48 | 48 |
public class Main : GLib.Object {
|
49 | |
|
|
49 |
|
50 | 50 |
public string app_path = "";
|
51 | 51 |
public string share_folder = "";
|
52 | 52 |
public string data_dir = "";
|
53 | 53 |
public string app_conf_path = "";
|
54 | 54 |
public string desktop = "gnome";
|
55 | |
|
|
55 |
|
56 | 56 |
public Gee.ArrayList<string> search_folders;
|
57 | 57 |
public Gee.ArrayList<ConkyRC> conkyrc_list;
|
58 | 58 |
public Gee.ArrayList<ConkyTheme> conkytheme_list;
|
59 | |
|
|
59 |
|
60 | 60 |
public bool is_aborted;
|
61 | 61 |
public string last_cmd;
|
62 | 62 |
|
|
76 | 76 |
public string[] bg_scaling_gnome = {"stretched","centered","tiled","stretched","scaled","zoomed"};
|
77 | 77 |
public string[] bg_scaling_xfce = {"0","1","2","3","4","5"};
|
78 | 78 |
public string[] bg_scaling_lxde = {"","center","tile","stretch","fit","crop"};
|
79 | |
|
|
79 |
|
80 | 80 |
public static int main(string[] args) {
|
81 | |
|
|
81 |
|
82 | 82 |
//set locale
|
83 | 83 |
Intl.setlocale(GLib.LocaleCategory.MESSAGES, "");
|
84 | 84 |
Intl.textdomain(GETTEXT_PACKAGE);
|
|
87 | 87 |
|
88 | 88 |
//init GTK
|
89 | 89 |
Gtk.init (ref args);
|
90 | |
|
|
90 |
|
91 | 91 |
//init TMP
|
92 | 92 |
init_tmp();
|
93 | |
|
|
93 |
|
94 | 94 |
//init app
|
95 | 95 |
App = new Main(args);
|
96 | |
|
|
96 |
|
97 | 97 |
//show window
|
98 | 98 |
var window = new MainWindow();
|
99 | 99 |
//quit app when window is closed
|
|
107 | 107 |
return false;
|
108 | 108 |
});
|
109 | 109 |
window.show_all();
|
110 | |
|
|
110 |
|
111 | 111 |
//run main loop
|
112 | 112 |
Gtk.main();
|
113 | 113 |
|
|
126 | 126 |
conkytheme_list = new Gee.ArrayList<ConkyTheme>();
|
127 | 127 |
|
128 | 128 |
//check dependencies ---------------------
|
129 | |
|
|
129 |
|
130 | 130 |
string message;
|
131 | 131 |
if (!check_dependencies(out message)){
|
132 | 132 |
string title = _("Missing Dependencies");
|
133 | 133 |
gtk_messagebox(title, message, null, true);
|
134 | 134 |
exit(0);
|
135 | 135 |
}
|
136 | |
|
|
136 |
|
137 | 137 |
//get desktop ---------------
|
138 | 138 |
desktop = get_desktop_name().down();
|
139 | 139 |
log_msg("Desktop: %s".printf(desktop));
|
140 | |
|
|
140 |
|
141 | 141 |
//install new theme packs and fonts ---------------
|
142 | |
|
|
142 |
|
143 | 143 |
init_directories();
|
144 | 144 |
init_theme_packs();
|
145 | 145 |
|
|
148 | 148 |
|
149 | 149 |
public bool check_dependencies(out string msg){
|
150 | 150 |
msg = "";
|
151 | |
|
|
151 |
|
152 | 152 |
string[] dependencies = { "conky", "rsync","killall","cp","rm","touch","7za","import" };
|
153 | 153 |
|
154 | 154 |
string path;
|
|
158 | 158 |
msg += " * " + cmd_tool + "\n";
|
159 | 159 |
}
|
160 | 160 |
}
|
161 | |
|
|
161 |
|
162 | 162 |
if (msg.length > 0){
|
163 | 163 |
msg = _("Commands listed below are not available") + ":\n\n" + msg + "\n";
|
164 | 164 |
msg += _("Please install required packages and try running it again");
|
|
169 | 169 |
return true;
|
170 | 170 |
}
|
171 | 171 |
}
|
172 | |
|
|
172 |
|
173 | 173 |
public void save_app_config(){
|
174 | 174 |
var config = new Json.Object();
|
175 | 175 |
|
176 | 176 |
string home = Environment.get_home_dir();
|
177 | |
|
|
177 |
|
178 | 178 |
config.set_string_member("capture_background", capture_background.to_string());
|
179 | 179 |
config.set_string_member("generate_png", generate_png.to_string());
|
180 | 180 |
config.set_string_member("show_preview", show_preview.to_string());
|
|
198 | 198 |
var node = new Json.Node(NodeType.OBJECT);
|
199 | 199 |
node.set_object(config);
|
200 | 200 |
json.set_root(node);
|
201 | |
|
|
201 |
|
202 | 202 |
try{
|
203 | 203 |
json.to_file(this.app_conf_path);
|
204 | 204 |
} catch (Error e) {
|
205 | 205 |
log_error (e.message);
|
206 | 206 |
}
|
207 | |
|
|
207 |
|
208 | 208 |
log_msg(_("App config saved") + ": '%s'".printf(app_conf_path));
|
209 | 209 |
}
|
210 | |
|
|
210 |
|
211 | 211 |
public void load_app_config(){
|
212 | 212 |
var f = File.new_for_path(app_conf_path);
|
213 | 213 |
if (!f.query_exists()) { return; }
|
214 | |
|
|
214 |
|
215 | 215 |
var parser = new Json.Parser();
|
216 | 216 |
try{
|
217 | 217 |
parser.load_from_file(this.app_conf_path);
|
|
231 | 231 |
startup_delay = json_get_int(config,"startup_delay",startup_delay);
|
232 | 232 |
|
233 | 233 |
// search folders -------------------
|
234 | |
|
|
234 |
|
235 | 235 |
search_folders.clear();
|
236 | |
|
|
236 |
|
237 | 237 |
string home = Environment.get_home_dir();
|
238 | |
|
|
238 |
|
239 | 239 |
//default locations: look for other folders in addition to "~/.conky"
|
240 | 240 |
foreach(string path in new string[]{ home + "/.Conky", home + "/.config/conky", home + "/.config/Conky"}){
|
241 | 241 |
if (!search_folders.contains(path) && dir_exists(path)){
|
|
255 | 255 |
|
256 | 256 |
log_msg(_("App config loaded") + ": '%s'".printf(this.app_conf_path));
|
257 | 257 |
}
|
258 | |
|
|
258 |
|
259 | 259 |
public void init_directories(){
|
260 | 260 |
string path = data_dir;
|
261 | 261 |
string home = Environment.get_home_dir ();
|
262 | |
|
|
262 |
|
263 | 263 |
if (dir_exists(path) == false){
|
264 | 264 |
create_dir(path);
|
265 | 265 |
log_debug(_("Directory Created") + ": " + path);
|
|
270 | 270 |
create_dir(path);
|
271 | 271 |
log_debug(_("Directory Created") + ": " + path);
|
272 | 272 |
}
|
273 | |
|
|
273 |
|
274 | 274 |
path = home + "/.config/autostart";
|
275 | 275 |
if (dir_exists(path) == false){
|
276 | 276 |
create_dir(path);
|
277 | 277 |
log_debug(_("Directory Created") + ": " + path);
|
278 | 278 |
}
|
279 | 279 |
}
|
280 | |
|
|
280 |
|
281 | 281 |
public void init_theme_packs(){
|
282 | 282 |
string sharePath = "/usr/share/conky-manager/themepacks";
|
283 | 283 |
string config_file = data_dir + "/.themepacks";
|
284 | |
|
|
284 |
|
285 | 285 |
//create empty config file if missing
|
286 | |
if (file_exists(config_file) == false) {
|
287 | |
Posix.system("touch \"" + config_file + "\"");
|
|
286 |
if (file_exists(config_file) == false) {
|
|
287 |
Posix.system("touch \"" + config_file + "\"");
|
288 | 288 |
}
|
289 | 289 |
|
290 | 290 |
//read config file
|
|
293 | 293 |
foreach(string item in txt.split("\n")){
|
294 | 294 |
filenames.add(item);
|
295 | 295 |
}
|
296 | |
|
|
296 |
|
297 | 297 |
//skip import of theme packs installed by previous versions of conky manager
|
298 | 298 |
filenames.add("default-themes-1.1.cmtp.7z");
|
299 | 299 |
filenames.add("default-themes-1.2.cmtp.7z");
|
300 | |
|
|
300 |
|
301 | 301 |
try{
|
302 | 302 |
FileEnumerator enumerator;
|
303 | 303 |
FileInfo file;
|
304 | 304 |
File fShare = File.parse_name (sharePath);
|
305 | |
|
|
305 |
|
306 | 306 |
if (dir_exists(sharePath)){
|
307 | 307 |
enumerator = fShare.enumerate_children ("standard::*", 0);
|
308 | |
|
|
308 |
|
309 | 309 |
while ((file = enumerator.next_file ()) != null) {
|
310 | |
|
|
310 |
|
311 | 311 |
string filePath = sharePath + "/" + file.get_name();
|
312 | 312 |
if (file_exists(filePath) == false) { continue; }
|
313 | 313 |
if (filePath.has_suffix(".cmtp.7z") == false) { continue; }
|
|
320 | 320 |
break;
|
321 | 321 |
}
|
322 | 322 |
}
|
323 | |
|
|
323 |
|
324 | 324 |
if (!is_installed){
|
325 | 325 |
log_msg("-----------------------------------------------------");
|
326 | 326 |
log_msg(_("Found theme pack [new]") + ": " + filePath);
|
327 | 327 |
install_theme_pack(filePath);
|
328 | 328 |
filenames.add(file.get_name());
|
329 | 329 |
log_msg("-----------------------------------------------------");
|
330 | |
|
|
330 |
|
331 | 331 |
string list = "";
|
332 | 332 |
foreach(string filename in filenames){
|
333 | 333 |
list += filename + "\n";
|
|
335 | 335 |
list += file.get_name() + "\n";
|
336 | 336 |
write_file(config_file,list);
|
337 | 337 |
}
|
338 | |
}
|
|
338 |
}
|
339 | 339 |
}
|
340 | 340 |
}
|
341 | 341 |
catch(Error e){
|
|
348 | 348 |
string std_out;
|
349 | 349 |
string std_err;
|
350 | 350 |
int ret_val;
|
351 | |
|
|
351 |
|
352 | 352 |
//create temp dir
|
353 | 353 |
string temp_dir = TEMP_DIR;
|
354 | 354 |
temp_dir = temp_dir + "/" + timestamp2();
|
355 | 355 |
create_dir(temp_dir);
|
356 | |
|
|
356 |
|
357 | 357 |
//check and create ~/.conky
|
358 | 358 |
if (dir_exists(data_dir) == false){
|
359 | 359 |
create_dir(data_dir);
|
360 | 360 |
}
|
361 | |
|
|
361 |
|
362 | 362 |
log_msg(_("Importing") + ": " + pkgPath);
|
363 | |
|
|
363 |
|
364 | 364 |
//unzip
|
365 | 365 |
cmd = "cd \"" + temp_dir + "\"\n";
|
366 | 366 |
cmd += "7za x \"" + pkgPath + "\">nul\n";
|
367 | |
|
|
367 |
|
368 | 368 |
ret_val = execute_command_script_sync(cmd, out std_out, out std_err);
|
369 | 369 |
if (ret_val != 0){
|
370 | 370 |
log_error(_("Failed to unzip files from theme pack"));
|
371 | 371 |
log_error (std_err);
|
372 | 372 |
return false;
|
373 | 373 |
}
|
374 | |
|
|
374 |
|
375 | 375 |
//install
|
376 | 376 |
foreach(string dirname in new string[]{".conky",".Conky",".fonts",".config/conky",".config/Conky"}){
|
377 | 377 |
string src_path = temp_dir + "/" + dirname;
|
378 | 378 |
string dst_path = Environment.get_home_dir() + "/" + dirname;
|
379 | |
|
|
379 |
|
380 | 380 |
if (dir_exists(src_path)){
|
381 | |
|
|
381 |
|
382 | 382 |
//create destination
|
383 | 383 |
if (!dir_exists(dst_path)){
|
384 | 384 |
create_dir(dst_path);
|
385 | 385 |
}
|
386 | |
|
|
386 |
|
387 | 387 |
//rsync folder
|
388 | 388 |
execute_command_sync("rsync -ai --numeric-ids '%s/' '%s'".printf(src_path,dst_path));
|
389 | 389 |
}
|
|
391 | 391 |
|
392 | 392 |
//delete temp files
|
393 | 393 |
Posix.system("rm -rf \"" + temp_dir + "\"");
|
394 | |
|
|
394 |
|
395 | 395 |
return true;
|
396 | 396 |
}
|
397 | |
|
|
397 |
|
398 | 398 |
public void load_themes_and_widgets() {
|
399 | 399 |
is_aborted = false;
|
400 | |
|
|
400 |
|
401 | 401 |
find_conkyrc_files();
|
402 | 402 |
find_conkytheme_files();
|
403 | 403 |
find_and_install_fonts();
|
404 | 404 |
refresh_conkyrc_status();
|
405 | |
|
|
405 |
|
406 | 406 |
log_msg(_("Searching for conkyrc files... %d found").printf(conkyrc_list.size));
|
407 | 407 |
}
|
408 | 408 |
|
|
410 | 410 |
is_aborted = true;
|
411 | 411 |
command_kill("grep",last_cmd);
|
412 | 412 |
}
|
413 | |
|
|
413 |
|
414 | 414 |
public void find_conkyrc_files(){
|
415 | 415 |
conkyrc_list = new Gee.ArrayList<ConkyRC>();
|
416 | 416 |
|
|
420 | 420 |
find_conkyrc_files_in_path(path);
|
421 | 421 |
}
|
422 | 422 |
}
|
423 | |
CompareFunc<ConkyConfigItem> func = (a, b) => {
|
|
423 |
CompareDataFunc<ConkyConfigItem> func = (a, b) => {
|
424 | 424 |
return strcmp(a.name,b.name);
|
425 | 425 |
};
|
426 | |
conkyrc_list.sort(func);
|
427 | |
}
|
428 | |
|
|
426 |
conkyrc_list.sort((owned) func);
|
|
427 |
}
|
|
428 |
|
429 | 429 |
public void find_conkyrc_files_in_path(string path){
|
430 | 430 |
string std_out = "";
|
431 | 431 |
string std_err = "";
|
432 | 432 |
string cmd = "grep -r \"^[[:blank:]]*TEXT[[:blank:]]*$\" \"%s\"".printf(path);
|
433 | 433 |
last_cmd = cmd;
|
434 | 434 |
int exit_code = execute_command_script_sync(cmd, out std_out, out std_err);
|
435 | |
|
436 | |
if (exit_code != 0){
|
|
435 |
|
|
436 |
if (exit_code != 0){
|
437 | 437 |
//no files found
|
438 | 438 |
return;
|
439 | 439 |
}
|
440 | |
|
|
440 |
|
441 | 441 |
string file_path;
|
442 | 442 |
foreach(string line in std_out.split("\n")){
|
443 | 443 |
if (line.index_of(":") > -1){
|
444 | 444 |
file_path = line.split(":")[0].strip();
|
445 | 445 |
if (file_path.strip().has_suffix("~")){ continue; }
|
446 | |
|
|
446 |
|
447 | 447 |
bool found = false;
|
448 | 448 |
foreach(ConkyConfigItem item in conkyrc_list){
|
449 | 449 |
if (item.path == file_path){
|
|
458 | 458 |
}
|
459 | 459 |
}
|
460 | 460 |
}
|
461 | |
|
|
461 |
|
462 | 462 |
public void find_conkytheme_files(){
|
463 | 463 |
conkytheme_list = new Gee.ArrayList<ConkyTheme>();
|
464 | 464 |
|
|
469 | 469 |
}
|
470 | 470 |
}
|
471 | 471 |
|
472 | |
CompareFunc<ConkyConfigItem> func = (a, b) => {
|
|
472 |
CompareDataFunc<ConkyConfigItem> func = (a, b) => {
|
473 | 473 |
return strcmp(a.name,b.name);
|
474 | 474 |
};
|
475 | |
conkytheme_list.sort(func);
|
|
475 |
conkytheme_list.sort((owned) func);
|
476 | 476 |
}
|
477 | 477 |
|
478 | 478 |
public void find_conkytheme_files_in_path(string path){
|
|
490 | 490 |
foreach(string line in std_out.split("\n")){
|
491 | 491 |
if (line == null){ continue; }
|
492 | 492 |
if (line.length == 0){ continue; }
|
493 | |
|
|
493 |
|
494 | 494 |
file_path = line.strip();
|
495 | 495 |
if (file_path.has_suffix("~")){ continue; }
|
496 | 496 |
if (!file_path.has_suffix(".cmtheme")){ continue; }
|
497 | 497 |
if (file_path.split(" ").length < 2){ continue; }
|
498 | 498 |
file_path = path + "/" + file_path[file_path.index_of(" ") + 1:file_path.length].strip();
|
499 | |
|
|
499 |
|
500 | 500 |
bool found = false;
|
501 | 501 |
foreach(ConkyConfigItem item in conkytheme_list){
|
502 | 502 |
if (item.path == file_path){
|
|
510 | 510 |
}
|
511 | 511 |
}
|
512 | 512 |
}
|
513 | |
|
|
513 |
|
514 | 514 |
public void find_and_install_fonts(){
|
515 | 515 |
find_and_install_fonts_in_path(data_dir);
|
516 | 516 |
foreach(string path in search_folders){
|
|
519 | 519 |
}
|
520 | 520 |
}
|
521 | 521 |
}
|
522 | |
|
|
522 |
|
523 | 523 |
public void find_and_install_fonts_in_path(string path){
|
524 | 524 |
string std_out = "";
|
525 | 525 |
string std_err = "";
|
|
539 | 539 |
file_path = line.strip();
|
540 | 540 |
if (file_path.has_suffix("~")){ continue; }
|
541 | 541 |
if (file_path.split(" ").length < 2){ continue; }
|
542 | |
|
|
542 |
|
543 | 543 |
if (file_path.has_suffix(".ttf")||file_path.has_suffix(".TTF")||file_path.has_suffix(".otf")||file_path.has_suffix(".OTF")){
|
544 | 544 |
//ok
|
545 | 545 |
}
|
|
548 | 548 |
}
|
549 | 549 |
|
550 | 550 |
file_path = path + "/" + file_path[file_path.index_of(" ") + 1:file_path.length].strip();
|
551 | |
|
|
551 |
|
552 | 552 |
File font_file = File.new_for_path (file_path);
|
553 | 553 |
string file_name = font_file.get_basename();
|
554 | 554 |
string home = Environment.get_home_dir ();
|
555 | 555 |
string target_file = home + "/.fonts/" + file_name;
|
556 | |
|
|
556 |
|
557 | 557 |
if (file_exists(target_file) == false){
|
558 | 558 |
copy_file(file_path, target_file);
|
559 | 559 |
log_msg(_("Font Copied: ") + target_file);
|
|
565 | 565 |
Gee.ArrayList<string> active_list = new Gee.ArrayList<string>();
|
566 | 566 |
|
567 | 567 |
string cmd = "conky -c "; //without double-quotes
|
568 | |
string txt = execute_command_sync_get_output ("ps w -C conky");
|
|
568 |
string txt = execute_command_sync_get_output ("ps w -C conky");
|
569 | 569 |
//use 'ps ew -C conky' for all users
|
570 | |
|
|
570 |
|
571 | 571 |
foreach(string line in txt.split("\n")){
|
572 | 572 |
if (line.index_of(cmd) != -1){
|
573 | 573 |
string conf = line.substring(line.index_of(cmd) + 8).strip();
|
574 | 574 |
active_list.add(conf);
|
575 | 575 |
}
|
576 | 576 |
}
|
577 | |
|
|
577 |
|
578 | 578 |
foreach(ConkyRC rc in conkyrc_list){
|
579 | 579 |
bool active = false;
|
580 | 580 |
foreach(string path in active_list){
|
|
585 | 585 |
rc.enabled = active;
|
586 | 586 |
}
|
587 | 587 |
}
|
588 | |
|
|
588 |
|
589 | 589 |
private void exit_app(){
|
590 | 590 |
update_startup_script();
|
591 | |
|
|
591 |
|
592 | 592 |
save_app_config();
|
593 | |
|
|
593 |
|
594 | 594 |
if (check_startup()){
|
595 | 595 |
autostart(true); //overwrite the startup entry
|
596 | 596 |
}
|
597 | 597 |
}
|
598 | |
|
|
598 |
|
599 | 599 |
public void run_startup_script(){
|
600 | 600 |
execute_command_sync("sh \"" + data_dir + "/conky-startup.sh\"");
|
601 | 601 |
Posix.usleep(500000);//microseconds
|
602 | 602 |
//refresh_status();
|
603 | 603 |
}
|
604 | |
|
|
604 |
|
605 | 605 |
public void update_startup_script(){
|
606 | 606 |
string startupScript = data_dir + "/conky-startup.sh";
|
607 | |
|
|
607 |
|
608 | 608 |
bool atleast_one_widget_enabled = false;
|
609 | |
|
|
609 |
|
610 | 610 |
string txt = "";
|
611 | 611 |
txt += "sleep %ds\n".printf(startup_delay);
|
612 | 612 |
txt += "killall conky\n";
|
|
617 | 617 |
atleast_one_widget_enabled = true;
|
618 | 618 |
}
|
619 | 619 |
}
|
620 | |
|
|
620 |
|
621 | 621 |
if (file_exists(startupScript)){
|
622 | 622 |
file_delete(startupScript);
|
623 | 623 |
}
|
624 | |
|
|
624 |
|
625 | 625 |
if (atleast_one_widget_enabled){
|
626 | 626 |
write_file(startupScript, txt);
|
627 | 627 |
}
|
|
629 | 629 |
write_file(startupScript, "# No widgets enabled!\n\nexit 0"); //write empty script
|
630 | 630 |
}
|
631 | 631 |
}
|
632 | |
|
|
632 |
|
633 | 633 |
public bool check_startup(){
|
634 | 634 |
string home = Environment.get_home_dir ();
|
635 | 635 |
string startupFile = home + "/.config/autostart/conky.desktop";
|
636 | |
return file_exists(startupFile);
|
637 | |
}
|
638 | |
|
|
636 |
return file_exists(startupFile);
|
|
637 |
}
|
|
638 |
|
639 | 639 |
public void autostart(bool autostart){
|
640 | 640 |
string home = Environment.get_home_dir ();
|
641 | 641 |
string startupFile = home + "/.config/autostart/conky.desktop";
|
642 | |
|
|
642 |
|
643 | 643 |
if (autostart){
|
644 | |
string txt =
|
|
644 |
string txt =
|
645 | 645 |
"""[Desktop Entry]
|
646 | 646 |
Type=Application
|
647 | 647 |
Exec={command}
|
|
654 | 654 |
Comment=
|
655 | 655 |
""";
|
656 | 656 |
txt = txt.replace("{command}", "sh \"" + data_dir + "/conky-startup.sh\"");
|
657 | |
|
|
657 |
|
658 | 658 |
write_file(startupFile, txt);
|
659 | 659 |
}
|
660 | 660 |
else{
|
661 | |
file_delete(startupFile);
|
662 | |
}
|
663 | |
}
|
664 | |
|
|
661 |
file_delete(startupFile);
|
|
662 |
}
|
|
663 |
}
|
|
664 |
|
665 | 665 |
public void kill_all_conky(){
|
666 | 666 |
Posix.system("killall conky");
|
667 | 667 |
foreach(ConkyRC rc in conkyrc_list){
|
|
680 | 680 |
private bool _enabled = false;
|
681 | 681 |
private string _url = "";
|
682 | 682 |
private string _credits = "";
|
683 | |
|
|
683 |
|
684 | 684 |
public abstract void start();
|
685 | 685 |
public abstract void stop();
|
686 | |
|
|
686 |
|
687 | 687 |
public void init_path(string theme_file_path){
|
688 | 688 |
path = theme_file_path;
|
689 | 689 |
var f = File.new_for_path (theme_file_path);
|
|
691 | 691 |
base_name = f.get_basename();
|
692 | 692 |
dir = f.get_parent().get_path();
|
693 | 693 |
}
|
694 | |
|
|
694 |
|
695 | 695 |
public void init_image_path(){
|
696 | |
|
|
696 |
|
697 | 697 |
string[] ext_list = {".png",".jpg",".jpeg"};
|
698 | |
|
|
698 |
|
699 | 699 |
//search using base name
|
700 | 700 |
foreach(string ext in ext_list){
|
701 | 701 |
image_path = dir + "/" + base_name + ext;
|
702 | 702 |
if (file_exists(image_path)){ return; }
|
703 | 703 |
}
|
704 | |
|
|
704 |
|
705 | 705 |
//search without basename extension
|
706 | 706 |
if (base_name.split(".").length == 2){
|
707 | 707 |
foreach(string ext in ext_list){
|
|
709 | 709 |
if (file_exists(image_path)){ return; }
|
710 | 710 |
}
|
711 | 711 |
}
|
712 | |
|
|
712 |
|
713 | 713 |
//search using fixed names
|
714 | 714 |
foreach(string ext in ext_list){
|
715 | 715 |
image_path = dir + "/preview" + ext;
|
716 | 716 |
if (file_exists(image_path)){ return; }
|
717 | 717 |
}
|
718 | |
|
|
718 |
|
719 | 719 |
image_path = ""; //clear if not found
|
720 | 720 |
}
|
721 | 721 |
|
|
730 | 730 |
credits = TeeJee.FileSystem.read_file(credits_file).replace("\n","");
|
731 | 731 |
}
|
732 | 732 |
}
|
733 | |
|
|
733 |
|
734 | 734 |
public string name{
|
735 | 735 |
get{
|
736 | 736 |
return _name;
|
|
739 | 739 |
_name = value;
|
740 | 740 |
}
|
741 | 741 |
}
|
742 | |
|
|
742 |
|
743 | 743 |
public string path{
|
744 | 744 |
get{
|
745 | 745 |
return _path;
|
|
757 | 757 |
_dir = value;
|
758 | 758 |
}
|
759 | 759 |
}
|
760 | |
|
|
760 |
|
761 | 761 |
public string image_path{
|
762 | 762 |
get{
|
763 | 763 |
return _image_path;
|
|
766 | 766 |
_image_path = value;
|
767 | 767 |
}
|
768 | 768 |
}
|
769 | |
|
|
769 |
|
770 | 770 |
public bool enabled{
|
771 | 771 |
get{
|
772 | 772 |
return _enabled;
|
|
793 | 793 |
_url = value;
|
794 | 794 |
}
|
795 | 795 |
}
|
796 | |
|
|
796 |
|
797 | 797 |
public string credits{
|
798 | 798 |
get{
|
799 | 799 |
return _credits;
|
|
802 | 802 |
_credits = value;
|
803 | 803 |
}
|
804 | 804 |
}
|
805 | |
|
|
805 |
|
806 | 806 |
}
|
807 | 807 |
|
808 | 808 |
public class ConkyRC : ConkyConfigItem {
|
809 | 809 |
public string text = "";
|
810 | |
|
|
810 |
|
811 | 811 |
private Regex rex_conky_win;
|
812 | 812 |
private MatchInfo match;
|
813 | |
|
|
813 |
|
814 | 814 |
private string err_line;
|
815 | 815 |
private string out_line;
|
816 | 816 |
private DataInputStream dis_out;
|
|
818 | 818 |
private bool thread_is_running = false;
|
819 | 819 |
private int wait_interval = 1;
|
820 | 820 |
private uint timer_stop;
|
821 | |
|
|
821 |
|
822 | 822 |
public ConkyRC(string rc_file_path) {
|
823 | 823 |
init_path(rc_file_path);
|
824 | 824 |
init_image_path();
|
|
831 | 831 |
log_error (e.message);
|
832 | 832 |
}
|
833 | 833 |
}
|
834 | |
|
|
834 |
|
835 | 835 |
public bool is_running(){
|
836 | 836 |
string cmd = "conky -c " + path; //without double-quotes
|
837 | |
string txt = execute_command_sync_get_output ("ps w -C conky");
|
|
837 |
string txt = execute_command_sync_get_output ("ps w -C conky");
|
838 | 838 |
//use 'ps ew -C conky' for all users
|
839 | |
|
|
839 |
|
840 | 840 |
bool active = false;
|
841 | 841 |
foreach(string line in txt.split("\n")){
|
842 | 842 |
if (line.index_of(cmd) != -1){
|
|
846 | 846 |
}
|
847 | 847 |
return active;
|
848 | 848 |
}
|
849 | |
|
|
849 |
|
850 | 850 |
public override void start(){
|
851 | 851 |
string cmd;
|
852 | 852 |
|
853 | 853 |
if (is_running()){
|
854 | 854 |
stop();
|
855 | 855 |
}
|
856 | |
|
|
856 |
|
857 | 857 |
//Theme.install();
|
858 | |
|
|
858 |
|
859 | 859 |
cmd = "cd \"" + dir + "\"\n";
|
860 | 860 |
cmd += "conky -c \"" + path + "\"\n";
|
861 | 861 |
|
|
863 | 863 |
|
864 | 864 |
Thread.usleep((ulong)1000000);
|
865 | 865 |
log_debug(_("Started") + ": " + path);
|
866 | |
|
|
866 |
|
867 | 867 |
//set the flag for immediate effect
|
868 | 868 |
//will be updated by the refresh_status() timer
|
869 | |
enabled = true;
|
|
869 |
enabled = true;
|
870 | 870 |
}
|
871 | 871 |
|
872 | 872 |
public bool stop_handler(){
|
873 | 873 |
stop();
|
874 | 874 |
return true;
|
875 | 875 |
}
|
876 | |
|
|
876 |
|
877 | 877 |
public override void stop(){
|
878 | |
|
|
878 |
|
879 | 879 |
//Note: There may be more than one running instance of the same config
|
880 | 880 |
//We need to kill all instances
|
881 | |
|
|
881 |
|
882 | 882 |
string cmd = "conky -c " + path; //without double-quotes
|
883 | 883 |
string txt = execute_command_sync_get_output ("ps w -C conky");
|
884 | 884 |
//use 'ps ew -C conky' for all users
|
885 | |
|
|
885 |
|
886 | 886 |
string pid = "";
|
887 | 887 |
foreach(string line in txt.split("\n")){
|
888 | 888 |
if (line.index_of(cmd) != -1){
|
|
891 | 891 |
log_debug(_("Stopped") + ": [PID=" + pid + "] " + path);
|
892 | 892 |
}
|
893 | 893 |
}
|
894 | |
|
|
894 |
|
895 | 895 |
//set the flag for immediate effect
|
896 | 896 |
//will be updated by the refresh_status() timer
|
897 | |
enabled = false;
|
898 | |
}
|
899 | |
|
|
897 |
enabled = false;
|
|
898 |
}
|
|
899 |
|
900 | 900 |
public void read_file(){
|
901 | 901 |
log_debug("Read config file from disk");
|
902 | 902 |
this.text = TeeJee.FileSystem.read_file(this.path);
|
903 | 903 |
}
|
904 | |
|
|
904 |
|
905 | 905 |
public void save_file(){
|
906 | 906 |
log_debug("Saved config file changes to disk");
|
907 | 907 |
write_file(this.path, text);
|
|
910 | 910 |
public void save_file_temp(){
|
911 | 911 |
write_file(this.path + "~temp~", text);
|
912 | 912 |
}
|
913 | |
|
|
913 |
|
914 | 914 |
public void delete_file_temp(){
|
915 | 915 |
file_delete(this.path + "~temp~");
|
916 | 916 |
}
|
917 | |
|
|
917 |
|
918 | 918 |
public bool generate_preview(){
|
919 | 919 |
stop();
|
920 | 920 |
read_file();
|
|
926 | 926 |
}
|
927 | 927 |
delete_file_temp();
|
928 | 928 |
save_file_temp();
|
929 | |
|
|
929 |
|
930 | 930 |
read_file();
|
931 | 931 |
wait_interval = 3;
|
932 | 932 |
foreach(string line in text.split("\n")){
|
|
935 | 935 |
break;
|
936 | 936 |
}
|
937 | 937 |
}
|
938 | |
|
|
938 |
|
939 | 939 |
try {
|
940 | 940 |
thread_is_running = true;
|
941 | 941 |
Thread.create<void> (generate_preview_thread, true);
|
|
959 | 959 |
return false;
|
960 | 960 |
}
|
961 | 961 |
}
|
962 | |
|
|
962 |
|
963 | 963 |
public void generate_preview_thread (){
|
964 | 964 |
string cmd = "cd \"" + dir + "\"\n";
|
965 | 965 |
cmd += "conky -c \"" + path + "~temp~\" 2>&1 \n";
|
966 | 966 |
|
967 | 967 |
string[] argv = new string[1];
|
968 | 968 |
argv[0] = create_temp_bash_script(cmd);
|
969 | |
|
|
969 |
|
970 | 970 |
Pid child_pid;
|
971 | 971 |
int input_fd;
|
972 | 972 |
int output_fd;
|
|
984 | 984 |
out input_fd,
|
985 | 985 |
out output_fd,
|
986 | 986 |
out error_fd);
|
987 | |
|
|
987 |
|
988 | 988 |
thread_is_running = true;
|
989 | |
|
|
989 |
|
990 | 990 |
timer_stop = Timeout.add (10 * 1000, stop_handler);
|
991 | |
|
|
991 |
|
992 | 992 |
//create stream readers
|
993 | 993 |
UnixInputStream uis_out = new UnixInputStream(output_fd, false);
|
994 | 994 |
UnixInputStream uis_err = new UnixInputStream(error_fd, false);
|
|
996 | 996 |
dis_err = new DataInputStream(uis_err);
|
997 | 997 |
dis_out.newline_type = DataStreamNewlineType.ANY;
|
998 | 998 |
dis_err.newline_type = DataStreamNewlineType.ANY;
|
999 | |
|
|
999 |
|
1000 | 1000 |
try {
|
1001 | 1001 |
//start thread for reading output stream
|
1002 | 1002 |
Thread.create<void> (conky_read_output_line, true);
|
1003 | 1003 |
} catch (Error e) {
|
1004 | 1004 |
log_error (e.message);
|
1005 | 1005 |
}
|
1006 | |
|
|
1006 |
|
1007 | 1007 |
try {
|
1008 | 1008 |
//start thread for reading error stream
|
1009 | 1009 |
Thread.create<void> (conky_read_error_line, true);
|
|
1026 | 1026 |
}
|
1027 | 1027 |
catch (Error e) {
|
1028 | 1028 |
log_error (e.message);
|
1029 | |
}
|
1030 | |
}
|
1031 | |
|
|
1029 |
}
|
|
1030 |
}
|
|
1031 |
|
1032 | 1032 |
private void conky_read_output_line(){
|
1033 | 1033 |
try{
|
1034 | 1034 |
out_line = dis_out.read_line (null);
|
1035 | 1035 |
while (out_line != null) {
|
1036 | 1036 |
if (rex_conky_win.match (out_line, 0, out match)){
|
1037 | |
|
|
1037 |
|
1038 | 1038 |
//wait for one second till window is displayed on screen
|
1039 | 1039 |
Thread.usleep ((ulong) wait_interval * 1000000);
|
1040 | |
|
|
1040 |
|
1041 | 1041 |
string win_id = match.fetch(1).strip();
|
1042 | 1042 |
string cmd = "";
|
1043 | |
|
|
1043 |
|
1044 | 1044 |
if (App.generate_png){
|
1045 | 1045 |
image_path = dir + "/" + base_name + ".png";
|
1046 | 1046 |
cmd = "import -window 0x%s '%s'".printf(win_id,image_path);
|
|
1049 | 1049 |
image_path = dir + "/" + base_name + ".jpg";
|
1050 | 1050 |
cmd = "import -window 0x%s -quality 90 '%s'".printf(win_id,image_path);
|
1051 | 1051 |
}
|
1052 | |
|
|
1052 |
|
1053 | 1053 |
execute_command_sync(cmd);
|
1054 | |
|
|
1054 |
|
1055 | 1055 |
Thread.usleep ((ulong) 100000); //wait 100ms before killing conky
|
1056 | |
|
|
1056 |
|
1057 | 1057 |
if (timer_stop > 0){
|
1058 | 1058 |
Source.remove(timer_stop);
|
1059 | 1059 |
timer_stop = 0;
|
|
1068 | 1068 |
}
|
1069 | 1069 |
catch (Error e) {
|
1070 | 1070 |
log_error (e.message);
|
1071 | |
}
|
|
1071 |
}
|
1072 | 1072 |
}
|
1073 | 1073 |
|
1074 | 1074 |
public string alignment{
|
1075 | 1075 |
owned get{
|
1076 | 1076 |
string s = get_value("alignment");
|
1077 | |
|
|
1077 |
|
1078 | 1078 |
switch(s){
|
1079 | 1079 |
case "tl":
|
1080 | 1080 |
s = "top_left";
|
|
1119 | 1119 |
log_debug("Set: alignment " + value);
|
1120 | 1120 |
}
|
1121 | 1121 |
}
|
1122 | |
|
|
1122 |
|
1123 | 1123 |
public string gap_x{
|
1124 | 1124 |
owned get{
|
1125 | 1125 |
string s = get_value("gap_x");
|
|
1134 | 1134 |
log_debug("Set: gap_x " + value);
|
1135 | 1135 |
}
|
1136 | 1136 |
}
|
1137 | |
|
|
1137 |
|
1138 | 1138 |
public string gap_y{
|
1139 | 1139 |
owned get{
|
1140 | 1140 |
string s = get_value("gap_y");
|
|
1149 | 1149 |
log_debug("Set: gap_y " + value);
|
1150 | 1150 |
}
|
1151 | 1151 |
}
|
1152 | |
|
|
1152 |
|
1153 | 1153 |
public string own_window_transparent{
|
1154 | 1154 |
owned get{
|
1155 | 1155 |
string s = get_value("own_window_transparent");
|
|
1164 | 1164 |
log_debug("Set: own_window_transparent " + value);
|
1165 | 1165 |
}
|
1166 | 1166 |
}
|
1167 | |
|
|
1167 |
|
1168 | 1168 |
public string own_window_argb_visual{
|
1169 | 1169 |
owned get{
|
1170 | 1170 |
string s = get_value("own_window_argb_visual");
|
|
1179 | 1179 |
log_debug("Set: own_window_argb_visual " + value);
|
1180 | 1180 |
}
|
1181 | 1181 |
}
|
1182 | |
|
|
1182 |
|
1183 | 1183 |
public string own_window_argb_value{
|
1184 | 1184 |
owned get{
|
1185 | 1185 |
string s = get_value("own_window_argb_value");
|
|
1194 | 1194 |
log_debug("Set: own_window_argb_value " + value);
|
1195 | 1195 |
}
|
1196 | 1196 |
}
|
1197 | |
|
|
1197 |
|
1198 | 1198 |
public string own_window_colour{
|
1199 | 1199 |
owned get{
|
1200 | 1200 |
string s = get_value("own_window_colour");
|
|
1208 | 1208 |
log_debug("Set: own_window_colour " + value.up());
|
1209 | 1209 |
}
|
1210 | 1210 |
}
|
1211 | |
|
|
1211 |
|
1212 | 1212 |
public string transparency{
|
1213 | 1213 |
owned get{
|
1214 | 1214 |
string s = "trans";
|
|
1247 | 1247 |
else{
|
1248 | 1248 |
s = "opaque";
|
1249 | 1249 |
}
|
1250 | |
|
|
1250 |
|
1251 | 1251 |
log_debug("Get: transparency " + s);
|
1252 | |
|
|
1252 |
|
1253 | 1253 |
return s;
|
1254 | 1254 |
}
|
1255 | 1255 |
set{
|
|
1273 | 1273 |
own_window_argb_visual = "yes";
|
1274 | 1274 |
break;
|
1275 | 1275 |
}
|
1276 | |
|
|
1276 |
|
1277 | 1277 |
log_debug("Set: transparency " + value.down());
|
1278 | 1278 |
}
|
1279 | 1279 |
}
|
1280 | |
|
|
1280 |
|
1281 | 1281 |
public string minimum_size{
|
1282 | 1282 |
owned get{
|
1283 | 1283 |
string s = get_value("minimum_size");
|
|
1292 | 1292 |
log_debug("Set: minimum_size " + value);
|
1293 | 1293 |
}
|
1294 | 1294 |
}
|
1295 | |
|
|
1295 |
|
1296 | 1296 |
public int height_padding{
|
1297 | 1297 |
get{
|
1298 | 1298 |
string[] arr = this.text.split("\n");
|
1299 | 1299 |
int count = 0;
|
1300 | |
|
|
1300 |
|
1301 | 1301 |
//count empty lines at end of the file
|
1302 | 1302 |
for(int k = arr.length - 1; k >= 0; k--){
|
1303 | 1303 |
if (arr[k].strip() == ""){
|
|
1307 | 1307 |
break;
|
1308 | 1308 |
}
|
1309 | 1309 |
}
|
1310 | |
|
|
1310 |
|
1311 | 1311 |
count--;
|
1312 | |
|
|
1312 |
|
1313 | 1313 |
log_debug("Get: height_padding " + count.to_string());
|
1314 | |
|
|
1314 |
|
1315 | 1315 |
return count;
|
1316 | 1316 |
}
|
1317 | 1317 |
set
|
|
1319 | 1319 |
string newText = "";
|
1320 | 1320 |
string[] arr = this.text.split("\n");
|
1321 | 1321 |
int count = 0;
|
1322 | |
|
|
1322 |
|
1323 | 1323 |
//count empty lines at end of the file
|
1324 | 1324 |
for(int k = arr.length - 1; k >= 0; k--){
|
1325 | 1325 |
if (arr[k].strip() == ""){
|
|
1329 | 1329 |
break;
|
1330 | 1330 |
}
|
1331 | 1331 |
}
|
1332 | |
|
|
1332 |
|
1333 | 1333 |
int lastLineNumber = arr.length - count;
|
1334 | |
|
|
1334 |
|
1335 | 1335 |
//remove all empty lines from end of text
|
1336 | 1336 |
for(int k = 0; k < lastLineNumber; k++){
|
1337 | 1337 |
newText += arr[k] + "\n";
|
1338 | 1338 |
}
|
1339 | 1339 |
//remove extra newline from end of text
|
1340 | 1340 |
//newText = newText[0:newText.length-1];
|
1341 | |
|
|
1341 |
|
1342 | 1342 |
//add empty lines at end of text
|
1343 | 1343 |
for(int k = 1; k <= value; k++){
|
1344 | 1344 |
newText += "\n";
|
1345 | 1345 |
}
|
1346 | |
|
|
1346 |
|
1347 | 1347 |
log_debug("Set: height_padding " + value.to_string());
|
1348 | |
|
|
1348 |
|
1349 | 1349 |
this.text = newText;
|
1350 | 1350 |
}
|
1351 | 1351 |
}
|
1352 | |
|
|
1352 |
|
1353 | 1353 |
public string time_format{
|
1354 | 1354 |
owned get{
|
1355 | 1355 |
string val = "";
|
1356 | |
|
|
1356 |
|
1357 | 1357 |
if (search("""\${(time|TIME) [^}]*H[^}]*}""") != ""){
|
1358 | 1358 |
val = "24";
|
1359 | 1359 |
log_debug("Get: time format = 24-hour");
|
|
1368 | 1368 |
set
|
1369 | 1369 |
{
|
1370 | 1370 |
if (value == "") { return; }
|
1371 | |
|
|
1371 |
|
1372 | 1372 |
switch(value){
|
1373 | 1373 |
case "12":
|
1374 | 1374 |
if (replace("""\${(time|TIME) [^}]*(H)[^}]*}""", 2, "I")){
|
|
1379 | 1379 |
if (replace("""\${(time|TIME) [^}]*(I)[^}]*}""", 2, "H")){
|
1380 | 1380 |
log_debug("Set: time format = 24-hour");
|
1381 | 1381 |
}
|
1382 | |
break;
|
1383 | |
}
|
1384 | |
}
|
1385 | |
}
|
1386 | |
|
|
1382 |
break;
|
|
1383 |
}
|
|
1384 |
}
|
|
1385 |
}
|
|
1386 |
|
1387 | 1387 |
public string network_device{
|
1388 | 1388 |
owned get{
|
1389 | 1389 |
string var1 = "totaldown|totalup|upspeed|upspeedf|downspeed|downspeedf|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode";
|
1390 | 1390 |
var1 = """\${(""" + var1 + "|" + var1.up() + """)[ \t]*([A-Za-z0-9]+)[ \t]*}""";
|
1391 | |
|
|
1391 |
|
1392 | 1392 |
string var2 = "upspeedgraph|downspeedgraph";
|
1393 | 1393 |
var2 = """\${(""" + var2 + "|" + var2.up() + """)[ \t]*([A-Za-z0-9]+)[ \t]*.*}""";
|
1394 | |
|
|
1394 |
|
1395 | 1395 |
string var3 = "wireless_link_bar";
|
1396 | 1396 |
var3 = """\${(""" + var3 + "|" + var3.up() + """)[ \t]*[0-9]+[ \t]*,[0-9+][ \t]*([A-Za-z0-9]+)[ \t]*}""";
|
1397 | 1397 |
|
1398 | 1398 |
string net = search(var1, 2);
|
1399 | |
|
|
1399 |
|
1400 | 1400 |
if (net != ""){
|
1401 | 1401 |
log_debug("Get: network interface = " + net);
|
1402 | 1402 |
return net;
|
1403 | 1403 |
}
|
1404 | |
|
|
1404 |
|
1405 | 1405 |
net = search(var2, 2);
|
1406 | |
|
|
1406 |
|
1407 | 1407 |
if (net != ""){
|
1408 | 1408 |
log_debug("Get: network interface = " + net);
|
1409 | 1409 |
return net;
|
1410 | 1410 |
}
|
1411 | |
|
|
1411 |
|
1412 | 1412 |
net = search(var3, 2);
|
1413 | |
|
|
1413 |
|
1414 | 1414 |
if (net != ""){
|
1415 | 1415 |
log_debug("Get: network interface = " + net);
|
1416 | 1416 |
return net;
|
1417 | 1417 |
}
|
1418 | |
|
|
1418 |
|
1419 | 1419 |
return "";
|
1420 | 1420 |
}
|
1421 | 1421 |
set
|
1422 | 1422 |
{
|
1423 | 1423 |
if (value == "") { return; }
|
1424 | |
|
|
1424 |
|
1425 | 1425 |
string var1 = "totaldown|totalup|upspeed|upspeedf|downspeed|downspeedf|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode";
|
1426 | 1426 |
var1 = """\${(""" + var1 + "|" + var1.up() + """)[ \t]*([A-Za-z0-9]+)[ \t]*}""";
|
1427 | |
|
|
1427 |
|
1428 | 1428 |
string var2 = "upspeedgraph|downspeedgraph";
|
1429 | 1429 |
var2 = """\${(""" + var2 + "|" + var2.up() + """)[ \t]*([A-Za-z0-9]+)[ \t]*.*}""";
|
1430 | |
|
|
1430 |
|
1431 | 1431 |
string var3 = "wireless_link_bar";
|
1432 | 1432 |
var3 = """\${(""" + var3 + "|" + var3.up() + """)[ \t]*[0-9]+[ \t]*,[0-9+][ \t]*([A-Za-z0-9]+)[ \t]*}""";
|
1433 | 1433 |
|
1434 | 1434 |
string net = search(var1, 2);
|
1435 | |
|
|
1435 |
|
1436 | 1436 |
if (net != ""){
|
1437 | 1437 |
if (replace(var1, 2, value)){
|
1438 | 1438 |
log_debug("Set: network interface = " + value);
|
1439 | 1439 |
}
|
1440 | 1440 |
}
|
1441 | |
|
|
1441 |
|
1442 | 1442 |
net = search(var2, 2);
|
1443 | |
|
|
1443 |
|
1444 | 1444 |
if (net != ""){
|
1445 | 1445 |
if (replace(var2, 2, value)){
|
1446 | 1446 |
log_debug("Set: network interface = " + value);
|
1447 | 1447 |
}
|
1448 | 1448 |
}
|
1449 | |
|
|
1449 |
|
1450 | 1450 |
net = search(var3, 2);
|
1451 | |
|
|
1451 |
|
1452 | 1452 |
if (net != ""){
|
1453 | 1453 |
if (replace(var3, 2, value)){
|
1454 | 1454 |
log_debug("Set: network interface = " + value);
|
|
1456 | 1456 |
}
|
1457 | 1457 |
}
|
1458 | 1458 |
}
|
1459 | |
|
|
1459 |
|
1460 | 1460 |
public string get_value(string param){
|
1461 | 1461 |
foreach(string line in this.text.split("\n")){
|
1462 | 1462 |
string s = line.down().strip();
|
|
1469 | 1469 |
}
|
1470 | 1470 |
}
|
1471 | 1471 |
}
|
1472 | |
|
|
1472 |
|
1473 | 1473 |
return "";
|
1474 | 1474 |
}
|
1475 | |
|
|
1475 |
|
1476 | 1476 |
public void set_value(string param, string newLine){
|
1477 | 1477 |
string newText = "";
|
1478 | 1478 |
bool found = false;
|
1479 | 1479 |
bool remove = (newLine.strip() == param);
|
1480 | |
|
|
1480 |
|
1481 | 1481 |
foreach(string line in this.text.split("\n")){
|
1482 | 1482 |
string s = line.down().strip();
|
1483 | 1483 |
if (s.has_prefix(param)){
|
|
1499 | 1499 |
newText += line + "\n";
|
1500 | 1500 |
}
|
1501 | 1501 |
}
|
1502 | |
|
|
1502 |
|
1503 | 1503 |
//remove extra newline from end of text
|
1504 | 1504 |
newText = newText[0:newText.length-1];
|
1505 | |
|
|
1505 |
|
1506 | 1506 |
this.text = newText;
|
1507 | 1507 |
}
|
1508 | |
|
|
1508 |
|
1509 | 1509 |
public string search(string search_string, int bracket_num = 0){
|
1510 | 1510 |
foreach(string line in this.text.split("\n")){
|
1511 | 1511 |
string s = line.strip();
|
|
1520 | 1520 |
log_error (e.message);
|
1521 | 1521 |
}
|
1522 | 1522 |
}
|
1523 | |
|
|
1523 |
|
1524 | 1524 |
return "";
|
1525 | 1525 |
}
|
1526 | |
|
|
1526 |
|
1527 | 1527 |
public bool replace(string search_string, int bracket_num, string replace_string){
|
1528 | 1528 |
bool found = false;
|
1529 | 1529 |
string new_text = "";
|
1530 | 1530 |
string old_match = "";
|
1531 | 1531 |
string new_match = "";
|
1532 | 1532 |
string new_line = "";
|
1533 | |
|
|
1533 |
|
1534 | 1534 |
foreach(string line in this.text.split("\n")){
|
1535 | 1535 |
try{
|
1536 | 1536 |
Regex regx = new Regex(search_string);
|
1537 | 1537 |
MatchInfo match;
|
1538 | 1538 |
if (regx.match(line, 0, out match)){
|
1539 | |
|
|
1539 |
|
1540 | 1540 |
bool matchExists = true;
|
1541 | 1541 |
new_line = line;
|
1542 | |
|
|
1542 |
|
1543 | 1543 |
while (matchExists){
|
1544 | 1544 |
old_match = match.fetch(0);
|
1545 | 1545 |
new_match = old_match.replace(match.fetch(bracket_num),replace_string);
|
|
1547 | 1547 |
new_line = new_line.replace(old_match, new_match);
|
1548 | 1548 |
matchExists = match.next();
|
1549 | 1549 |
}
|
1550 | |
|
|
1550 |
|
1551 | 1551 |
new_text += new_line + "\n";
|
1552 | 1552 |
found = true;
|
1553 | 1553 |
}
|
|
1559 | 1559 |
return false;
|
1560 | 1560 |
}
|
1561 | 1561 |
}
|
1562 | |
|
|
1562 |
|
1563 | 1563 |
//remove extra newline from end of text
|
1564 | 1564 |
new_text = new_text[0:new_text.length-1];
|
1565 | |
|
|
1565 |
|
1566 | 1566 |
this.text = new_text;
|
1567 | |
|
|
1567 |
|
1568 | 1568 |
return found;
|
1569 | 1569 |
}
|
1570 | 1570 |
}
|
|
1573 | 1573 |
public string wallpaper_path = "";
|
1574 | 1574 |
public string text = "";
|
1575 | 1575 |
public string wallpaper_scaling = "";
|
1576 | |
|
|
1576 |
|
1577 | 1577 |
public Gee.ArrayList<ConkyRC> conkyrc_list;
|
1578 | 1578 |
private Main main_app;
|
1579 | |
|
|
1579 |
|
1580 | 1580 |
public ConkyTheme.empty(string theme_file_path){
|
1581 | 1581 |
init_path(theme_file_path);
|
1582 | 1582 |
conkyrc_list = new Gee.ArrayList<ConkyRC>();
|
1583 | 1583 |
}
|
1584 | |
|
|
1584 |
|
1585 | 1585 |
public ConkyTheme.from_file(string theme_file_path, Main _main_app){
|
1586 | 1586 |
main_app = _main_app;
|
1587 | 1587 |
init_path(theme_file_path);
|
1588 | 1588 |
init_image_path();
|
1589 | 1589 |
init_credits();
|
1590 | |
|
|
1590 |
|
1591 | 1591 |
conkyrc_list = new Gee.ArrayList<ConkyRC>();
|
1592 | 1592 |
foreach(string line in read_file(theme_file_path).split("\n")){
|
1593 | 1593 |
//remove quotes
|
|
1597 | 1597 |
if (line.has_suffix("\"")){
|
1598 | 1598 |
line = line[0:line.length-1];
|
1599 | 1599 |
}
|
1600 | |
|
|
1600 |
|
1601 | 1601 |
//read options
|
1602 | 1602 |
if (line.contains("wallpaper-scaling") && (line.split(":").length == 2)){
|
1603 | 1603 |
string val = line.split(":")[1].strip().down();
|
1604 | |
|
|
1604 |
|
1605 | 1605 |
//check if option is valid
|
1606 | 1606 |
bool valid = false;
|
1607 | 1607 |
foreach(string option in App.bg_scaling){
|
|
1610 | 1610 |
break;
|
1611 | 1611 |
}
|
1612 | 1612 |
}
|
1613 | |
|
|
1613 |
|
1614 | 1614 |
if (valid){
|
1615 | 1615 |
wallpaper_scaling = val;
|
1616 | 1616 |
continue;
|
|
1619 | 1619 |
continue;
|
1620 | 1620 |
}
|
1621 | 1621 |
}
|
1622 | |
|
|
1622 |
|
1623 | 1623 |
//read wallpaper path
|
1624 | 1624 |
if (line.has_suffix(".png")||line.has_suffix(".jpg")||line.has_suffix(".jpeg")){
|
1625 | 1625 |
wallpaper_path = line.replace("~", Environment.get_home_dir());
|
|
1639 | 1639 |
|
1640 | 1640 |
public void init_wallpaper_path(){
|
1641 | 1641 |
string[] ext_list = {".png",".jpg",".jpeg"};
|
1642 | |
|
|
1642 |
|
1643 | 1643 |
foreach(string ext in ext_list){
|
1644 | 1644 |
wallpaper_path = dir + "/wallpaper" + ext;
|
1645 | 1645 |
if (file_exists(wallpaper_path)){ return; }
|
|
1647 | 1647 |
|
1648 | 1648 |
wallpaper_path = "";
|
1649 | 1649 |
}
|
1650 | |
|
|
1650 |
|
1651 | 1651 |
public void set_wallpaper(){
|
1652 | 1652 |
if ((wallpaper_path.length > 0)&&(file_exists(wallpaper_path))){
|
1653 | 1653 |
switch (App.desktop){
|
|
1679 | 1679 |
cmd += "xfconf-query -c xfce4-desktop -p '%s' -s '%s'".printf(property.strip(), wallpaper_path);
|
1680 | 1680 |
string std_out2, std_err2;
|
1681 | 1681 |
execute_command_script_sync(cmd, out std_out2, out std_err2);
|
1682 | |
}
|
|
1682 |
}
|
1683 | 1683 |
break;
|
1684 | 1684 |
case "lxde": //limited support - wallpaper changes after logout and login
|
1685 | 1685 |
execute_command_sync("pcmanfm --set-wallpaper '%s'".printf(wallpaper_path));
|
|
1687 | 1687 |
execute_command_sync("pcmanfm --wallpaper-mode '%s'".printf(get_scaling_value_for_desktop()));
|
1688 | 1688 |
}
|
1689 | 1689 |
break;
|
1690 | |
case "gnome":
|
|
1690 |
case "gnome":
|
1691 | 1691 |
case "unity":
|
1692 | 1692 |
if (execute_command_sync("gsettings get org.gnome.desktop.background picture-uri") == 0){
|
1693 | 1693 |
execute_command_sync("gsettings set org.gnome.desktop.background picture-uri 'file://%s'".printf(wallpaper_path));
|
1694 | 1694 |
}
|
1695 | |
|
|
1695 |
|
1696 | 1696 |
if (execute_command_sync("gsettings get org.gnome.desktop.background picture-options") == 0){
|
1697 | 1697 |
execute_command_sync("gsettings set org.gnome.desktop.background picture-options '%s'".printf(get_scaling_value_for_desktop()));
|
1698 | 1698 |
}
|
1699 | |
|
|
1699 |
|
1700 | 1700 |
if (execute_command_sync("gsettings get com.canonical.unity-greeter background") == 0){
|
1701 | 1701 |
execute_command_sync("gsettings set com.canonical.unity-greeter background '%s'".printf(wallpaper_path));
|
1702 | 1702 |
}
|
1703 | 1703 |
break;
|
1704 | 1704 |
}
|
1705 | |
|
1706 | |
|
|
1705 |
|
|
1706 |
|
1707 | 1707 |
/*if (wallpaper_scaling.length > 0){
|
1708 | 1708 |
Posix.system("feh --bg-%s '%s'".printf(wallpaper_scaling,wallpaper_path));
|
1709 | 1709 |
}
|
|
1712 | 1712 |
}*/
|
1713 | 1713 |
}
|
1714 | 1714 |
}
|
1715 | |
|
|
1715 |
|
1716 | 1716 |
public string get_scaling_value_for_desktop(){
|
1717 | 1717 |
//get index
|
1718 | 1718 |
int index = 0;
|
|
1737 | 1737 |
default:
|
1738 | 1738 |
return "";
|
1739 | 1739 |
}
|
1740 | |
|
1741 | |
}
|
1742 | |
|
|
1740 |
|
|
1741 |
}
|
|
1742 |
|
1743 | 1743 |
public string get_current_wallpaper(){
|
1744 | 1744 |
switch (App.desktop){
|
1745 | 1745 |
case "gnome":
|
|
1788 | 1788 |
rc.start();
|
1789 | 1789 |
}
|
1790 | 1790 |
}
|
1791 | |
|
|
1791 |
|
1792 | 1792 |
public override void stop(){
|
1793 | 1793 |
main_app.kill_all_conky();
|
1794 | 1794 |
}
|