00001 #include "appconfig.h"
00002 #include "main.h"
00003
00004 #include <QRect>
00005
00006
00007
00008 QSettings appconfig::conf("conf.ini",QSettings::IniFormat);
00009
00010
00011
00012 appconfig::appconfig(QObject *pobj)
00013 {
00014 Q_UNUSED(pobj);
00015
00016
00017 QFile conffile("conf.ini");
00018 if(!conffile.exists())
00019 critical_error("File conf.ini not found.");
00020
00021 conf.setPath(QSettings::IniFormat,QSettings::UserScope,"./");
00022 conf.setPath(QSettings::IniFormat,QSettings::SystemScope,"./");
00023 }
00024
00025
00026
00027 appconfig::~appconfig()
00028 {
00029
00030 }
00031
00032
00033
00034 QString appconfig::get_parameter(QString line)
00035 {
00036 QString t=conf.value(line).toString();
00037
00038 if(t.length()==0)
00039 critical_error("In config not found parameter " + line);
00040
00041 return t;
00042 }
00043
00044
00045
00046
00047 bool appconfig::set_tetradir(QString dirname)
00048 {
00049 QDir directory(dirname);
00050
00051 if(directory.exists() && directory.isReadable())
00052 {
00053 conf.setValue("tetradir",dirname);
00054 return true;
00055 }
00056 else
00057 return false;
00058 }
00059
00060
00061
00062 QString appconfig::get_tetradir(void)
00063 {
00064 return get_parameter("tetradir");
00065 }
00066
00067
00068
00069 bool appconfig::set_trashdir(QString dirname)
00070 {
00071 QDir directory(dirname);
00072
00073 if(directory.exists() && directory.isReadable())
00074 {
00075 conf.setValue("trashdir",dirname);
00076 return true;
00077 }
00078 else
00079 return false;
00080 }
00081
00082
00083
00084 QString appconfig::get_trashdir(void)
00085 {
00086 return get_parameter("trashdir");
00087 }
00088
00089
00090
00091 int appconfig::get_lastnotenum(void)
00092 {
00093 bool ok;
00094 int n;
00095
00096 n=get_parameter("lastnotenum").toInt(&ok, 10);
00097
00098 return n;
00099 }
00100
00101
00102
00103 QString appconfig::get_lastnotenum_as_line(void)
00104 {
00105 QString line=get_parameter("lastnotenum");
00106
00107 QString t=line.rightJustified(10, '0');
00108
00109 return t;
00110 }
00111
00112
00113
00114 void appconfig::inc_lastnotenum(void)
00115 {
00116 int i;
00117
00118 i=get_lastnotenum();
00119 i++;
00120
00121 conf.setValue("lastnotenum",i);
00122 }
00123
00124
00125
00126 int appconfig::get_lastidnum(void)
00127 {
00128 bool ok;
00129 int n;
00130
00131 n=get_parameter("lastidnum").toInt(&ok, 10);
00132
00133 return n;
00134 }
00135
00136
00137
00138 void appconfig::inc_lastidnum(void)
00139 {
00140 int i;
00141
00142 i=get_lastidnum();
00143 i++;
00144
00145 conf.setValue("lastidnum",i);
00146 }
00147
00148
00149
00150 int appconfig::get_lastprefixnum(void)
00151 {
00152 bool ok;
00153 int n;
00154
00155 n=get_parameter("lastprefixnum").toInt(&ok, 10);
00156
00157 return n;
00158 }
00159
00160
00161
00162 QString appconfig::get_lastprefixnum_as_line(void)
00163 {
00164 QString line=get_parameter("lastprefixnum");
00165
00166 QString t=line.rightJustified(10, '0');
00167
00168 return t;
00169 }
00170
00171
00172
00173 void appconfig::inc_lastprefixnum(void)
00174 {
00175 int i;
00176
00177 i=get_lastprefixnum();
00178 i++;
00179
00180 conf.setValue("lastprefixnum",i);
00181 }
00182
00183 QString appconfig::get_addnewrecord_expand_info(void)
00184 {
00185 return get_parameter("addnewrecord_expand_info");
00186 }
00187
00188 void appconfig::set_addnewrecord_expand_info(QString state)
00189 {
00190 if(state=="0" || state=="1")
00191 conf.setValue("addnewrecord_expand_info",state);
00192 else
00193 critical_error("Set unavailable value for addnewrecord_expand_info "+state);
00194 }
00195
00196
00197 QRect appconfig::get_mainwingeometry(void)
00198 {
00199 return conf.value("mainwingeometry",QRect(0,0,500,400)).toRect();
00200 }
00201
00202
00203 void appconfig::set_mainwingeometry(int x, int y, int w, int h)
00204 {
00205 QRect winrectangle(x,y,w,h);
00206 conf.setValue("mainwingeometry",winrectangle);
00207 }
00208
00209
00210 QList<int> appconfig::get_vspl_size_list(void)
00211 {
00212 return get_splitter_size_list("vspl");
00213 }
00214
00215
00216 void appconfig::set_vspl_size_list(QList<int> list)
00217 {
00218 set_splitter_size_list("vspl", list);
00219 }
00220
00221
00222 QList<int> appconfig::get_hspl_size_list(void)
00223 {
00224 return get_splitter_size_list("hspl");
00225 }
00226
00227
00228 void appconfig::set_hspl_size_list(QList<int> list)
00229 {
00230 set_splitter_size_list("hspl", list);
00231 }
00232
00233
00234 QList<int> appconfig::get_findsplitter_size_list(void)
00235 {
00236 return get_splitter_size_list("findsplitter");
00237 }
00238
00239
00240 void appconfig::set_findsplitter_size_list(QList<int> list)
00241 {
00242 set_splitter_size_list("findsplitter", list);
00243 }
00244
00245
00246 QList<int> appconfig::get_splitter_size_list(QString name)
00247 {
00248 QStringList line_list;
00249 QList<int> list;
00250
00251 line_list=(conf.value(name+"_size_list","100,100")).toString().split(",");
00252
00253 for(int i=0;i < line_list.size(); ++i)
00254 list.append( line_list.at(i).toInt() );
00255
00256 return list;
00257 }
00258
00259
00260 void appconfig::set_splitter_size_list(QString name, QList<int> list)
00261 {
00262 QStringList line_list;
00263
00264 for(int i=0;i < list.size(); ++i)
00265 line_list.append( QString::number(list.at(i)) );
00266
00267 conf.setValue(name+"_size_list",line_list.join(","));
00268 }
00269
00270
00271 QStringList appconfig::get_tree_position(void)
00272 {
00273 return (conf.value("tree_position","1")).toString().split(",");
00274 }
00275
00276
00277 void appconfig::set_tree_position(QStringList list)
00278 {
00279 conf.setValue("tree_position",list.join(","));
00280 }
00281
00282
00283 int appconfig::get_recordtable_position(void)
00284 {
00285 return conf.value("recordtable_position",0).toInt();
00286 }
00287
00288
00289 void appconfig::set_recordtable_position(int pos)
00290 {
00291 conf.setValue("recordtable_position",pos);
00292 }
00293
00294
00295 int appconfig::get_findscreen_wordregard(void)
00296 {
00297 return conf.value("findscreen_wordregard",0).toInt();
00298 }
00299
00300
00301 void appconfig::set_findscreen_wordregard(int pos)
00302 {
00303 conf.setValue("findscreen_wordregard",pos);
00304 }
00305
00306
00307 int appconfig::get_findscreen_howextract(void)
00308 {
00309 return conf.value("findscreen_howextract",0).toInt();
00310 }
00311
00312
00313 void appconfig::set_findscreen_howextract(int pos)
00314 {
00315 conf.setValue("findscreen_howextract",pos);
00316 }
00317
00318
00319 bool appconfig::get_findscreen_find_in_field(QString fieldname)
00320 {
00321 return conf.value("findscreen_find_in"+fieldname,0).toBool();
00322 }
00323
00324
00325 void appconfig::set_findscreen_find_in_field(QString fieldname, bool ischecked)
00326 {
00327 conf.setValue("findscreen_find_in"+fieldname,ischecked);
00328 }
00329
00330
00331 bool appconfig::get_findscreen_show(void)
00332 {
00333 return conf.value("findscreen_show",0).toBool();
00334 }
00335
00336
00337 void appconfig::set_findscreen_show(bool isshow)
00338 {
00339 conf.setValue("findscreen_show",isshow);
00340 }
00341