2
2
This file is part of RoboJournal.
3
3
Copyright (c) 2012 by Will Kraft <pwizard@gmail.com>.
6
6
RoboJournal is free software: you can redistribute it and/or modify
7
7
it under the terms of the GNU General Public License as published by
34
34
#include "ui/newconfig.h"
35
#include "core/favoritecore.h"
36
39
/* This class is meant to be a full *replacement* of the ConfigManager class from RoboJournal 0.1-0.3.
37
40
* Once SettingManager has been fully implemented, ConfigManager is to be deprecated and removed
38
41
* from the source package. (deprecation completed by 2/26/13)
41
SettingsManager::SettingsManager(){}
44
SettingsManager::SettingsManager(){
46
fail_param="[FAILED]";
49
//###################################################################################################
50
// Remember the page most recently viewed in the documentation window so the user can pick up where
51
// he/she left off on the previous session. New for 0.5. --Will Kraft (7/20/14).
52
void SettingsManager::Save_HelpDoc(QString path){
54
QString config_path=QDir::homePath()+ QDir::separator() + ".robojournal"+ QDir::separator() + "robojournal.ini";
55
QSettings settings(config_path,QSettings::IniFormat);
57
settings.beginGroup("Behavior");
58
settings.setValue("help_page", path);
63
//###################################################################################################
64
// Save the current path ($path) to MySQLDump. This is used exclusively on Windows so RoboJournal can
65
// remember where MySQLdump is. Unnecessary on linux b/c mysqldump is always stored in /usr/bin. --Will Kraft, (9/2/13).
66
void SettingsManager::Save_Mysqldump_Path(QString path){
68
QString config_path=QDir::homePath()+ QDir::separator() + ".robojournal"+ QDir::separator() + "robojournal.ini";
69
QSettings settings(config_path,QSettings::IniFormat);
71
settings.beginGroup("Behavior");
72
settings.setValue("mysqldump_path_win",path);
75
// Save and reload config after making changes because this function is called during app runtime.
43
81
//###################################################################################################
44
82
// Saves the current splitter position from the MainWindow. This allows someone to customize it once
45
83
// and have it stay that way. This should only be called when the mainwindow closes.
46
// New feature for 0.5-- Will Kraft, 6/21/13. Backported to 0.4.2 (9/13/13).
84
// New feature for 0.5. -- Will Kraft, 6/21/13
48
86
void SettingsManager::SaveSplitterPos(QByteArray value){
58
96
//###################################################################################################
59
98
// Save the behavior if the user opts to disable the tagging nag screen. This function should NOT
60
99
// be called from the preferences window! New for 0.4.1; 2/26/13
61
100
void SettingsManager::SaveNagPreferences(){
64
103
QSettings settings(config_path,QSettings::IniFormat);
66
105
settings.beginGroup("Behavior");
67
settings.setValue("show_untagged_reminder", Buffer::show_reminder_next_time);
106
settings.setValue("show_untagged_reminder", Buffer::show_reminder_next_time);
68
107
settings.endGroup();
70
// Save and Reload Config after making changes
109
// Save and reload config after making changes because this function is called during app runtime.
140
176
// install dictionaries to ~/.robojournal folder if necessary. This function makes sure the dictionaries
141
177
// are available and reinstalls them if necessary. New for 0.4.
142
178
void SettingsManager::InstallDictionaries(){
143
180
using namespace std;
145
182
QString path= QDir::homePath() + QDir::separator() + ".robojournal" + QDir::separator();
183
path=QDir::toNativeSeparators(path);
147
185
QFile EN_dict(path + "en_US.dic");
148
186
QFile EN_dict_aff(path + "en_US.aff");
188
cout << "OUTPUT: Searching for default (US English) dictionary.........";
152
190
if((!EN_dict.exists()) || (!EN_dict_aff.exists())){
154
//qt_ntfs_permission_lookup++;
192
cout << fail_param << endl;
156
194
QFile d1(":/en_US.dic");
157
195
d1.copy(":/en_US.dic", path + "en_US.dic");
161
197
QFile d2(":/en_US.aff");
162
198
d2.copy(":/en_US.aff", path + "en_US.aff");
165
cout << "OUTPUT: Reinstalled (English US) dictionaries to" << path.toStdString() << endl;
167
//qt_ntfs_permission_lookup--;
200
cout << "OUTPUT: Reinstalled (English US) dictionaries to " << path.toStdString() << endl;
171
cout << "OUTPUT: Found default (English US) dictionary at" << path.toStdString() << endl;
204
cout << ok_param << endl;
173
if((!EN_dict.isWritable()) || (!EN_dict_aff.isWritable())){
174
cout << "OUTPUT: Making sure the dictionary is writable........";
206
if((!EN_dict.isWritable()) && (!EN_dict_aff.isWritable())){
207
cout << "OUTPUT: Making sure the dictionary is writable................";
175
208
EN_dict.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther);
176
209
EN_dict_aff.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther);
177
cout << "DONE!" << endl;
210
cout << ok_param << endl;
180
213
cout << "OUTPUT: Dictionary is properly writable. Proceeding with startup." << endl;
187
218
//###################################################################################################
188
219
// Get the user's full name
189
220
QString SettingsManager::FullName(){
265
296
settings.setValue("entry_range", 4);
266
297
settings.endGroup();
299
// New SQLite options for RoboJournal 0.5
300
settings.beginGroup("SQLite");
301
settings.setValue("use_my_journals", true);
302
settings.setValue("sqlite_favorites","");
303
settings.setValue("sqlite_default","");
268
306
settings.beginGroup("Behavior");
269
307
settings.setValue("toolbar_location", 1);
270
308
settings.setValue("allow_root_login", false);
279
317
settings.setValue("set_date_format", 1);
280
318
settings.setValue("enable_rich_text", false);
281
319
settings.setValue("use_dow", true);
320
settings.setValue("open_editor", true);
322
// Update for 0.5: never enable tooblar button text by default. This feature is actually
323
// deprecated as of 6/21/13 because it wastes too much space. Undeprecated b/c the font issue has been solved now.
284
324
if((!Buffer::show_icon_labels) && (!Buffer::firstrun)){
285
settings.setValue("enable_toolbar_button_text", false);
325
settings.setValue("enable_toolbar_button_text", false);
288
settings.setValue("enable_toolbar_button_text", true);
328
settings.setValue("enable_toolbar_button_text", false);
291
331
settings.setValue("autoload_recent_entry", true);
301
341
// Bugfix: Keep dictionary and AFF blank in new configurations.
302
342
settings.setValue("spellcheck_dictionary", "");
303
343
settings.setValue("spellcheck_dictionary_aff", "");
344
settings.setValue("system_dictionaries",false);
305
345
settings.setValue("misc_processing",true);
306
346
settings.setValue("name_in_titlebar", true);
307
347
settings.setValue("show_untagged_reminder", true);
344
384
settings.setValue("use_full_name", false);
347
settings.setValue("use_full_name", true);
387
settings.setValue("use_full_name", true);
350
390
settings.endGroup();
360
400
// Install dictionaries now so they are available immediately after firstrun is finished.
361
401
InstallDictionaries();
403
//Create new favorites database. Meant to be a 5.0 bugfix to fix a problem that kept this
404
// from happening during firstrun --Will Kraft (5/31/14).
406
f.Setup_Favorites_Database();
363
408
// Firstrun is now finished, allow the program to load normally by reading new config.
367
413
//##################################################################################
368
void SettingsManager::LoadConfig(){
414
// Load the current raw config data from the robojournal.ini file and buffer it.
415
void SettingsManager::LoadConfig(bool startup){
369
416
using namespace std;
371
418
bool reload=false;
375
422
// construct a file object where the config file is supposed to be.
376
423
QFile config(config_path);
377
cout << "OUTPUT: Searching for config file..." << endl;
426
cout << "OUTPUT: Searching for config file.............................";
379
428
// if config file exists, read its contents
380
429
if(config.exists()){
432
cout << ok_param << endl;
383
435
// Use backslashes to separate dirs on Windows.
384
config_path=config_path.replace("/","\\");
436
config_path=QDir::toNativeSeparators(config_path);
387
cout << "OUTPUT: Config file found: "<< config_path.toStdString() << endl;
439
//cout << "OUTPUT: Config file found: "<< config_path.toStdString() << endl;
388
440
QSettings settings(config_path,QSettings::IniFormat);
389
cout << "OUTPUT: Buffering data from config file...";
442
cout << "OUTPUT: Buffering data from config file.......................";
391
444
Buffer::toolbar_pos = settings.value("Behavior/toolbar_location").toInt();
392
445
Buffer::allowroot = settings.value("Behavior/allow_root_login").toBool();
444
497
Buffer::use_spellcheck = settings.value("Behavior/use_spellcheck").toBool();
445
498
Buffer::current_dictionary= settings.value("Behavior/spellcheck_dictionary").toString();
446
499
Buffer::current_dictionary_aff = settings.value("Behavior/spellcheck_dictionary_aff").toString();
500
Buffer::system_dic=settings.value("Behavior/system_dictionaries").toBool();
448
502
int font_value=settings.value("Appearance/font_size").toInt();
542
596
// 0.4.2 ( backported to 0.4.2 on 9/13/13)
543
597
Buffer::mw_splitter_size=settings.value("Behavior/mw_splitter_position").toByteArray(); // added 6/21/13
549
cout << "Done!" << endl;
550
cout << "OUTPUT: Stage 1 completed, proceeding to Stage 2..." << endl;
605
cout << ok_param << endl;
607
cout << "OUTPUT: Stage 1 completed, proceeding to Stage 2." << endl;
553
611
// if config doesn't exist, rebuild it.
555
cout << "WARNING: Config file does not exist! Starting first run mode..." << endl;
614
cout << fail_param << endl;
615
cout << "OUTPUT: Starting first run mode to replace missing configuration." << endl;
557
618
// give the journal creator a way to know its the first run
558
619
Buffer::firstrun=true;
582
643
settings.setValue("entry_range", Newconfig::new_entry_range);
583
644
settings.endGroup();
646
// New SQLite options for RoboJournal 0.5
647
settings.beginGroup("SQLite");
648
settings.setValue("use_my_journals", Newconfig::new_use_my_journals);
649
settings.setValue("sqlite_favorites", Newconfig::new_sqlite_favorites);
650
settings.setValue("sqlite_default", Newconfig::new_sqlite_default);
585
654
settings.beginGroup("Behavior");
586
655
settings.setValue("toolbar_location", Newconfig::new_toolbar_pos);
587
656
settings.setValue("allow_root_login", Newconfig::new_allow_root);
611
680
settings.setValue("misc_processing",Newconfig::new_use_misc_processing);
612
681
settings.setValue("name_in_titlebar", Newconfig::new_name_in_titlebar);
613
682
settings.setValue("show_untagged_reminder", Newconfig::new_show_untagged_reminder);
683
settings.setValue("system_dictionaries", Newconfig::new_system_dic);
684
settings.setValue("open_editor", Newconfig::new_open_editor);
614
685
settings.endGroup();
616
687
settings.beginGroup("Appearance");