~ubuntu-branches/ubuntu/vivid/robojournal/vivid-proposed

« back to all changes in this revision

Viewing changes to core/settingsmanager.cpp

  • Committer: Package Import Robot
  • Author(s): Ritesh Raj Sarraf
  • Date: 2014-10-14 15:50:21 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20141014155021-gjd34w00cquge8jf
Tags: 0.5-1
* [d7ce610] Imported Upstream version 0.5
* [ff3b609] Refine what is in the docs/
* [c1e0474] Add doc-base registration
* [68cd341] Install upstream provided xpm icon
* [a627af4] Add patch to override hardcoded doc location

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    This file is part of RoboJournal.
3
3
    Copyright (c) 2012 by Will Kraft <pwizard@gmail.com>.
4
 
    MADE IN USA
 
4
    
5
5
 
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
32
32
#include <QDir>
33
33
#include <QFile>
34
34
#include "ui/newconfig.h"
 
35
#include "core/favoritecore.h"
 
36
 
 
37
 
35
38
 
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)
39
42
 */
40
43
 
41
 
SettingsManager::SettingsManager(){}
 
44
SettingsManager::SettingsManager(){
 
45
    ok_param="[OK]";
 
46
    fail_param="[FAILED]";
 
47
}
 
48
 
 
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){
 
53
 
 
54
    QString config_path=QDir::homePath()+ QDir::separator() + ".robojournal"+ QDir::separator() + "robojournal.ini";
 
55
    QSettings settings(config_path,QSettings::IniFormat);
 
56
 
 
57
    settings.beginGroup("Behavior");
 
58
    settings.setValue("help_page", path);
 
59
    settings.endGroup();
 
60
}
 
61
 
 
62
 
 
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){
 
67
 
 
68
    QString config_path=QDir::homePath()+ QDir::separator() + ".robojournal"+ QDir::separator() + "robojournal.ini";
 
69
    QSettings settings(config_path,QSettings::IniFormat);
 
70
 
 
71
    settings.beginGroup("Behavior");
 
72
    settings.setValue("mysqldump_path_win",path);
 
73
    settings.endGroup();
 
74
 
 
75
    // Save and reload config after making changes because this function is called during app runtime.
 
76
    settings.sync();
 
77
    LoadConfig(false);
 
78
}
 
79
 
42
80
 
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
47
85
 
48
86
void SettingsManager::SaveSplitterPos(QByteArray value){
49
87
 
56
94
}
57
95
 
58
96
//###################################################################################################
 
97
 
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);
65
104
 
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();
69
108
 
70
 
    // Save and Reload Config after making changes
 
109
    // Save and reload config after making changes because this function is called during app runtime.
71
110
    settings.sync();
72
 
    LoadConfig();
 
111
    LoadConfig(false);
73
112
 
74
113
}
75
114
 
83
122
    settings.beginGroup("Appearance");
84
123
    settings.setValue("preview_size", geo);
85
124
    settings.endGroup();
86
 
 
87
125
}
88
126
 
89
127
 
98
136
    settings.beginGroup("Appearance");
99
137
    settings.setValue("config_size", geo);
100
138
    settings.endGroup();
101
 
 
102
 
 
103
139
}
104
140
 
105
141
 
117
153
 
118
154
    //settings.sync();
119
155
 
120
 
   // LoadConfig();
 
156
    // LoadConfig();
121
157
}
122
158
 
123
159
//###################################################################################################
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(){
 
179
 
143
180
    using namespace std;
144
181
 
145
182
    QString path= QDir::homePath() + QDir::separator() + ".robojournal" + QDir::separator();
 
183
    path=QDir::toNativeSeparators(path);
146
184
 
147
185
    QFile EN_dict(path + "en_US.dic");
148
186
    QFile EN_dict_aff(path +  "en_US.aff");
149
187
 
150
 
 
 
188
    cout << "OUTPUT: Searching for default (US English) dictionary.........";
151
189
 
152
190
    if((!EN_dict.exists()) || (!EN_dict_aff.exists())){
153
191
 
154
 
        //qt_ntfs_permission_lookup++;
 
192
        cout << fail_param << endl;
155
193
 
156
194
        QFile d1(":/en_US.dic");
157
195
        d1.copy(":/en_US.dic", path + "en_US.dic");
158
196
 
159
 
 
160
 
 
161
197
        QFile d2(":/en_US.aff");
162
198
        d2.copy(":/en_US.aff", path + "en_US.aff");
163
199
 
164
 
 
165
 
        cout << "OUTPUT: Reinstalled (English US) dictionaries to" << path.toStdString() << endl;
166
 
 
167
 
        //qt_ntfs_permission_lookup--;
168
 
 
 
200
        cout << "OUTPUT: Reinstalled (English US) dictionaries to " << path.toStdString() << endl;
169
201
    }
 
202
 
170
203
    else{
171
 
        cout << "OUTPUT: Found default (English US) dictionary at" << path.toStdString() << endl;
 
204
        cout << ok_param << endl;
172
205
 
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;
178
211
        }
179
212
        else{
180
213
            cout << "OUTPUT: Dictionary is properly writable. Proceeding with startup." << endl;
181
214
        }
182
215
    }
183
 
 
184
216
}
185
217
 
186
 
 
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();
267
298
 
 
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","");
 
304
    settings.endGroup();
 
305
 
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);
282
 
 
283
 
 
 
320
    settings.setValue("open_editor", true);
 
321
 
 
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);
286
326
    }
287
327
    else{
288
 
       settings.setValue("enable_toolbar_button_text", true);
 
328
        settings.setValue("enable_toolbar_button_text", false);
289
329
    }
290
330
 
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", "");
304
 
 
 
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);
345
385
    }
346
386
    else{
347
 
       settings.setValue("use_full_name", true);
 
387
        settings.setValue("use_full_name", true);
348
388
    }
349
389
 
350
390
    settings.endGroup();
360
400
    // Install dictionaries now so they are available immediately after firstrun is finished.
361
401
    InstallDictionaries();
362
402
 
 
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).
 
405
    FavoriteCore f;
 
406
    f.Setup_Favorites_Database();
 
407
 
363
408
    // Firstrun is now finished, allow the program to load normally by reading new config.
364
 
    LoadConfig();
 
409
    LoadConfig(true);
365
410
}
366
411
 
 
412
 
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;
370
417
 
371
418
    bool reload=false;
374
421
 
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;
 
424
 
 
425
    if(startup)
 
426
        cout << "OUTPUT: Searching for config file.............................";
378
427
 
379
428
    // if config file exists, read its contents
380
429
    if(config.exists()){
381
430
 
 
431
            if(startup)
 
432
        cout << ok_param << endl;
 
433
 
382
434
#ifdef _WIN32
383
435
        // Use backslashes to separate dirs on Windows.
384
 
        config_path=config_path.replace("/","\\");
 
436
        config_path=QDir::toNativeSeparators(config_path);
385
437
#endif
386
438
 
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...";
 
441
        if(startup)
 
442
            cout << "OUTPUT: Buffering data from config file.......................";
390
443
 
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();
447
501
 
448
502
        int font_value=settings.value("Appearance/font_size").toInt();
449
503
 
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
544
598
 
 
599
 
545
600
        if(reload){
546
 
            LoadConfig();
547
 
        }
548
 
 
549
 
        cout << "Done!" << endl;
550
 
        cout << "OUTPUT: Stage 1 completed, proceeding to Stage 2..." << endl;
 
601
            LoadConfig(false);
 
602
        }
 
603
 
 
604
        if(startup){
 
605
            cout << ok_param << endl;
 
606
 
 
607
            cout << "OUTPUT: Stage 1 completed, proceeding to Stage 2." << endl;
 
608
        }
551
609
    }
552
610
 
553
611
    // if config doesn't exist, rebuild it.
554
612
    else{
555
 
        cout << "WARNING: Config file does not exist! Starting first run mode..." << endl;
 
613
        if(startup){
 
614
            cout << fail_param << endl;
 
615
            cout << "OUTPUT: Starting first run mode to replace missing configuration." << endl;
 
616
        }
556
617
 
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();
584
645
 
 
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);
 
651
    settings.endGroup();
 
652
 
 
653
 
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();
615
686
 
616
687
    settings.beginGroup("Appearance");