Replace getenv("HOME") by RDGetHomeDir() in RDCutDialog::LoadState/SaveState. Create RDCutDialog::StateFile to share logic

This commit is contained in:
Alban Peignier 2014-09-05 09:50:32 +02:00
parent ea73b88634
commit 135e200331
2 changed files with 24 additions and 5 deletions

View File

@ -35,6 +35,8 @@
#include <rdadd_cart.h> #include <rdadd_cart.h>
#include <rdprofile.h> #include <rdprofile.h>
#include <rddb.h> #include <rddb.h>
#include <rdconf.h>
// //
// Icons // Icons
@ -641,14 +643,29 @@ void RDCutDialog::BuildGroupList()
} }
} }
QString RDCutDialog::StateFile() {
bool home_found = false;
QString home = RDGetHomeDir(&home_found);
if (home_found) {
return QString().sprintf("%s/.rdcartdialog",(const char *)home);
} else {
return NULL;
}
}
void RDCutDialog::LoadState() void RDCutDialog::LoadState()
{ {
if(getenv("HOME")==NULL) { QString state_file = StateFile();
if (state_file == NULL) {
return; return;
} }
RDProfile *p=new RDProfile(); RDProfile *p=new RDProfile();
p->setSource(QString().sprintf("%s/.rdcartdialog",getenv("HOME"))); p->setSource(state_file);
bool value_read = false;
cart_limit_box->setChecked(p->boolValue("RDCartDialog", "LimitSearch", true, &value_read));
delete p; delete p;
} }
@ -657,11 +674,12 @@ void RDCutDialog::SaveState()
{ {
FILE *f=NULL; FILE *f=NULL;
if(getenv("HOME")==NULL) { QString state_file = StateFile();
if (state_file == NULL) {
return; return;
} }
if((f=fopen(QString().sprintf("%s/.rdcartdialog",getenv("HOME")),"w"))==
NULL) { if((f=fopen(state_file,"w"))==NULL) {
return; return;
} }
fprintf(f,"[RDCartDialog]\n"); fprintf(f,"[RDCartDialog]\n");

View File

@ -74,6 +74,7 @@ class RDCutDialog : public QDialog
void RefreshCuts(); void RefreshCuts();
void SelectCut(QString cutname); void SelectCut(QString cutname);
void BuildGroupList(); void BuildGroupList();
QString StateFile();
void LoadState(); void LoadState();
void SaveState(); void SaveState();
RDListView *cut_cart_list; RDListView *cut_cart_list;