X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcommon%2Fpreferences.cpp;h=e965f486a03cf0ae3cbbe31b976a5b484f573388;hb=89a5f60f67b881c9a38a276a249d165d6fb4bd9a;hp=218b7b09a986ab7f65ab6ef7ec9eed50453a3994;hpb=45729fca56479bd9158486e0cda0c4a94b4dd1dc;p=xestiaab%2F.git
diff --git a/source/common/preferences.cpp b/source/common/preferences.cpp
index 218b7b0..e965f48 100644
--- a/source/common/preferences.cpp
+++ b/source/common/preferences.cpp
@@ -1,3 +1,21 @@
+// preferences.cpp - Preferences subroutines.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see
+
#include
#include
#include
@@ -12,49 +30,49 @@ void SavePreferences();
void LoadPreferences();
XABPreferences::XABPreferences(wxString PreferencesFilename){
+
+ // Load the settings into the XABPreferences object using the
+ // settings file received in PreferencesFilename.
+
+ wxString fullprefpath;
- //fstream preffile;
- wxString fullprefpath;
-
- int accountnum = 0;
-
- bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
- accountsslvalid, accountusernamevalid, accountpasswordvalid,
- accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
+ bool accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
+ accountsslvalid, accountusernamevalid, accountpasswordvalid,
+ accountdirprefixvalid, accountdirvalid, accountrefreshvalid = FALSE;
- bool preaccountstage = FALSE;
- bool isvalidaccount = FALSE;
- bool isvalidsection = FALSE;
- wxString accountname;
- wxString accountaddress;
- wxString accounttype;
- long accountport = 8080;
- long accountrefresh;
- bool accountssl;
- wxString accountusername;
- wxString accountpassword;
- wxString accountdirprefix;
- wxString accountdir;
+ bool preaccountstage = FALSE;
+ bool isvalidaccount = FALSE;
+ bool isvalidsection = FALSE;
+ wxString accountname;
+ wxString accountaddress;
+ wxString accounttype;
+ long accountport = 8080;
+ long accountrefresh;
+ bool accountssl;
+ wxString accountusername;
+ wxString accountpassword;
+ wxString accountdirprefix;
+ wxString accountdir;
- wxString firstchar;
- string s;
+ wxString firstchar;
+ string s;
- wxString segmentname;
- wxString segmentvalue;
+ wxString segmentname;
+ wxString segmentvalue;
- // Load the settings.
+ // Load the settings.
- fullprefpath.Append(PreferencesFilename);
- fullprefpath.Append(wxT("settings"));
+ fullprefpath.Append(PreferencesFilename);
+ fullprefpath.Append(wxT("settings"));
- wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
+ wxFileConfig *settingfile = new wxFileConfig("", "", fullprefpath);
- wxString ValueInc;
- settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
+ wxString ValueInc;
+ settingfile->Read(wxT("SaveWindowPosition"), &ValueInc);
- if (ValueInc == wxT("true")){
+ if (ValueInc == wxT("true")){
- SaveWindowPos = TRUE;
+ SaveWindowPos = true;
wxRect WindowPosition;
long PosX, PosY, PosH, PosW = 0;
@@ -68,10 +86,10 @@ XABPreferences::XABPreferences(wxString PreferencesFilename){
if (PosXValid == TRUE && PosYValid == TRUE && PosHValid == TRUE && PosWValid == TRUE){
- WindowPosition.SetX(PosX);
- WindowPosition.SetY(PosY);
- WindowPosition.SetHeight(PosH);
- WindowPosition.SetWidth(PosW);
+ WindowPosition.SetX((int)PosX);
+ WindowPosition.SetY((int)PosY);
+ WindowPosition.SetHeight((int)PosH);
+ WindowPosition.SetWidth((int)PosW);
} else {
@@ -84,158 +102,228 @@ XABPreferences::XABPreferences(wxString PreferencesFilename){
SetMainWindowData(WindowPosition);
- }
+ }
- settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
+ settingfile->Read(wxT("HideLocalAddressBooks"), &ValueInc);
- if (ValueInc == wxT("true")){
- HideLocalABs = TRUE;
- }
+ if (ValueInc == wxT("true")){
+ HideLocalABs = true;
+ }
+
+ settingfile->Read(wxT("UseBackgroundContactColour"), &ValueInc);
- delete settingfile;
- settingfile = NULL;
+ if (ValueInc == wxT("true")){
+ UseBackgroundContactColour = true;
+ wxString BackgroundContactColourRead;
+ settingfile->Read(wxT("BackgroundContactColour"), &BackgroundContactColourRead);
+ if (BackgroundContactColourRead.Mid(0, 1) == "#"){
+ BackgroundContactColour.Set(BackgroundContactColourRead);
+ }
+ }
- // Load the accounts.
+ delete settingfile;
+ settingfile = NULL;
- fullprefpath.Clear();
- fullprefpath.Append(PreferencesFilename);
- fullprefpath.Append(wxT("accounts"));
+ // Load the accounts.
+
+ fullprefpath.Clear();
+ fullprefpath.Append(PreferencesFilename);
+ fullprefpath.Append(wxT("accounts"));
- wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
+ wxFileConfig *cfgfile = new wxFileConfig("AddressBook", "Xestia", fullprefpath);
- wxString EntryName, EntryValue;
- wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
- wxString AccSSLInc;
- bool AccSSL = FALSE;
- int AccRef, AccPort = 0;
- long itemindex = 0;
- long subitemindex = 0;
- bool ContinueAcc = TRUE;
- bool ContinueProc = TRUE;
+ wxString EntryName, EntryValue;
+ wxString AccAdr, AccUsr, AccPass, AccPrefix, AccDir;
+ wxString AccSSLInc;
+ bool AccSSL = FALSE;
+ int AccRef, AccPort = 0;
+ long itemindex = 0;
+ bool ContinueAcc = TRUE;
- ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
+ ContinueAcc = cfgfile->GetFirstGroup(accountname, itemindex);
- while (ContinueAcc){
-
- cfgfile->SetPath(accountname);
- //ContinueProc = cfgfile->GetFirstEntry(EntryName, subitemindex);
- cfgfile->Read(wxT("type"), &EntryValue);
-
- if (EntryValue == wxT("Local")){
+ while (ContinueAcc){
+
+ cfgfile->SetPath(accountname);
+ cfgfile->Read(wxT("type"), &EntryValue);
+
+ if (EntryValue == wxT("Local")){
+
+ // Get the account directory.
- // Get the account directory.
-
- cfgfile->Read(wxT("accountdir"), &AccDir);
-
- if (AccDir.Len() > 4){
-
- accountdirvalid = TRUE;
-
+ cfgfile->Read(wxT("accountdir"), &AccDir);
+
+ if (AccDir.Len() > 4){
+
+ accountdirvalid = TRUE;
+
+ } else {
+
+ accountdirvalid = FALSE;
+
+ }
+
+ if (accountdirvalid == TRUE){
+
+ accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
+ 0, wxT(""), wxT(""),
+ wxT(""), AccDir, 0);
+
+ }
+
+ } else if (EntryValue == wxT("CardDAV")){
+
+ cfgfile->Read(wxT("accountdir"), &AccDir);
+ accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
+ accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
+ accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
+ if (AccSSLInc == wxT("true")){
+ AccSSL = TRUE;
+ }
+ else {
+ AccSSL = FALSE;
+ }
+ accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
+ accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
+ accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
+ accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
+
+ if (AccDir.Len() > 4){
+
+ accountdirvalid = TRUE;
+
+ }
+
+ // Make sure it is not bigger than 65535 or less than 1.
+ // If so, default to port 8008.
+
+ if (accountport < 1 || accountport > 65535){
+ accountport = 8008;
+ accountportvalid = TRUE;
+ }
+
+ accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
+ AccSSL, AccUsr, AccPass,
+ AccPrefix, AccDir, AccRef);
+
} else {
-
- accountdirvalid = FALSE;
-
- }
-
- if (accountdirvalid == TRUE){
-
- accounts.AddAccount(accountname, wxT("Local"), wxT(""), 0,
- 0, wxT(""), wxT(""),
- wxT(""), AccDir, 0);
-
- }
-
- } else if (EntryValue == wxT("CardDAV")){
-
- cfgfile->Read(wxT("accountdir"), &AccDir);
- accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
- accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
- accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
- if (AccSSLInc == wxT("true")){
- AccSSL = TRUE;
- }
- accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
- accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
- accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
- accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
-
- if (AccDir.Len() > 4){
-
- accountdirvalid = TRUE;
-
- }
- // Make sure it is not bigger than 65535 or less than 1.
- // If so, default to port 8008.
+ cfgfile->Read(wxT("accountdir"), &AccDir);
+ accountaddressvalid = cfgfile->Read(wxT("address"), &AccAdr);
+ accountportvalid = cfgfile->Read(wxT("port"), &AccPort);
+ accountsslvalid = cfgfile->Read(wxT("ssl"), &AccSSLInc);
+ if (AccSSLInc == wxT("true")){
+ AccSSL = TRUE;
+ }
+ else {
+ AccSSL = FALSE;
+ }
+ accountusernamevalid = cfgfile->Read(wxT("username"), &AccUsr);
+ accountpasswordvalid = cfgfile->Read(wxT("password"), &AccPass);
+ accountdirprefixvalid = cfgfile->Read(wxT("prefix"), &AccPrefix);
+ accountrefreshvalid = cfgfile->Read(wxT("refresh"), &AccRef);
+
+ if (AccDir.Len() > 4){
+
+ accountdirvalid = TRUE;
+
+ }
+
+ // Make sure it is not bigger than 65535 or less than 1.
+ // If so, default to port 8008.
+
+ if (accountport < 1 || accountport > 65535){
+ accountport = 8008;
+ accountportvalid = TRUE;
+ }
+
+ accounts.AddAccount(accountname, EntryValue, AccAdr, AccPort,
+ AccSSL, AccUsr, AccPass,
+ AccPrefix, AccDir, AccRef);
- if (accountport < 1 || accountport > 65535){
- accountport = 8008;
- accountportvalid = TRUE;
}
-
- accounts.AddAccount(accountname, wxT("CardDAV"), AccAdr, AccPort,
- AccSSL, AccUsr, AccPass,
- AccPrefix, AccDir, AccRef);
-
- }
- // Clear up for the next account.
+ // Clear up for the next account.
+
+ accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
+ accountsslvalid, accountusernamevalid, accountpasswordvalid,
+ accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
+ isvalidaccount, isvalidsection = FALSE;
+
+ AccAdr.Clear();
+ AccDir.Clear();
+ AccUsr.Clear();
+ AccPass.Clear();
+ AccPrefix.Clear();
+ accountname.Clear();
+ accountaddress.Clear();
+ accounttype.Clear();
+ accountport = 0;
+ accountrefresh = 0;
+ accountusername.Clear();
+ accountpassword.Clear();
+ accountdirprefix.Clear();
+ preaccountstage = TRUE;
- accountnamevalid, accountaddressvalid, accounttypevalid, accountportvalid,
- accountsslvalid, accountusernamevalid, accountpasswordvalid,
- accountdirprefixvalid, accountdirvalid, accountrefreshvalid, accountssl,
- isvalidaccount, isvalidsection = FALSE;
- AccAdr.Clear();
- //AccPort.Clear();
- AccDir.Clear();
- AccUsr.Clear();
- AccPass.Clear();
- AccPrefix.Clear();
- accountname.Clear();
- accountaddress.Clear();
- accounttype.Clear();
- accountport = 0;
- accountrefresh = 0;
- accountusername.Clear();
- accountpassword.Clear();
- accountdirprefix.Clear();
- preaccountstage = TRUE;
+ cfgfile->SetPath(wxT("/"));
+ ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
- cfgfile->SetPath(wxT("/"));
- ContinueAcc = cfgfile->GetNextGroup(accountname, itemindex);
- }
+ }
}
XABPreferences::~XABPreferences(){
-
+
}
bool XABPreferences::GetBoolData(wxString SettingName){
+ // GetBoolData from the XABPreferences object.
+
if (SettingName == wxT("SaveWindowPosition")) { return SaveWindowPos; }
else if (SettingName == wxT("HideLocalAddressBooks")) { return HideLocalABs; }
+ else if (SettingName == wxT("UseBackgroundContactColour")) { return UseBackgroundContactColour; }
- return FALSE;
+ return false;
}
wxRect XABPreferences::GetMainWindowData(){
+ // Return the main window data as a wxRect object.
+
return MainWindowData;
}
void XABPreferences::SetMainWindowData(wxRect WindowData){
+ // Set the main window data from a wxRect object.
+
MainWindowData = WindowData;
}
+wxColour XABPreferences::GetBackgroundContactColourData(){
+
+ return BackgroundContactColour;
+
+}
+
+void XABPreferences::SetBackgroundContactColourData(wxColour ColourData){
+
+ BackgroundContactColour = ColourData;
+
+}
+
// XABPrefAccounts
XABPrefAccounts::XABPrefAccounts(){
- AccountsCount = 0;
+
+ // Setup the default values for XABPrefAccounts.
+
+ AccountsCount = 0;
+
}
int XABPrefAccounts::AddAccount(wxString NewAccName,
@@ -250,18 +338,21 @@ int XABPrefAccounts::AddAccount(wxString NewAccName,
long NewAccRefresh
){
- AccountName.Add(NewAccName, 1);
- AccountType.Add(NewAccType, 1);
- AccountAddress.Add(NewAccAddress, 1);
- AccountPort.Add(NewAccPort, 1);
- AccountSSL.Add(NewAccSSL, 1);
- AccountUsername.Add(NewAccUser, 1);
- AccountPassword.Add(NewAccPass, 1);
- DirectoryPrefix.Add(NewAccDirPrefix, 1);
- AccountDirectory.Add(NewAccDir, 1);
- AccountRefresh.Add(NewAccRefresh, 1);
+ // Add an account to the list of accounts in the
+ // XABPrefAccounts object.
+
+ AccountName.Add(NewAccName, 1);
+ AccountType.Add(NewAccType, 1);
+ AccountAddress.Add(NewAccAddress, 1);
+ AccountPort.Add(NewAccPort, 1);
+ AccountSSL.Add(NewAccSSL, 1);
+ AccountUsername.Add(NewAccUser, 1);
+ AccountPassword.Add(NewAccPass, 1);
+ DirectoryPrefix.Add(NewAccDirPrefix, 1);
+ AccountDirectory.Add(NewAccDir, 1);
+ AccountRefresh.Add(NewAccRefresh, 1);
- AccountsCount++;
+ AccountsCount++;
return 0;
@@ -269,106 +360,128 @@ int XABPrefAccounts::AddAccount(wxString NewAccName,
int XABPrefAccounts::GetCount(){
- return AccountsCount;
+ // Get the count of accounts in the XABPrefAccounts object.
+
+ return AccountsCount;
}
wxString XABPrefAccounts::GetAccountName(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account name.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountName[AccountNum];
+ return AccountName[AccountNum];
}
wxString XABPrefAccounts::GetAccountType(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account type.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountType[AccountNum];
+ return AccountType[AccountNum];
}
wxString XABPrefAccounts::GetAccountAddress(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account server address.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountAddress[AccountNum];
+ return AccountAddress[AccountNum];
}
int XABPrefAccounts::GetAccountPort(int AccountNum){
- if (AccountNum > AccountsCount){
- return 0;
- }
+ // Get the account server port.
+
+ if (AccountNum > AccountsCount){
+ return 0;
+ }
- return AccountPort[AccountNum];
+ return AccountPort[AccountNum];
}
bool XABPrefAccounts::GetAccountSSL(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account server SSL support.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountSSL[AccountNum];
+ return AccountSSL[AccountNum];
}
wxString XABPrefAccounts::GetAccountUsername(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account username.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountUsername[AccountNum];
+ return AccountUsername[AccountNum];
}
wxString XABPrefAccounts::GetAccountPassword(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account password.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountPassword[AccountNum];
+ return AccountPassword[AccountNum];
}
wxString XABPrefAccounts::GetAccountDirectory(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account directory.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return AccountDirectory[AccountNum];
+ return AccountDirectory[AccountNum];
}
wxString XABPrefAccounts::GetAccountDirPrefix(int AccountNum){
- if (AccountNum > AccountsCount){
- return wxT("");
- }
+ // Get the account server directory prefix.
+
+ if (AccountNum > AccountsCount){
+ return wxT("");
+ }
- return DirectoryPrefix[AccountNum];
+ return DirectoryPrefix[AccountNum];
}
long XABPrefAccounts::GetAccountRefresh(int AccountNum){
- if (AccountNum > AccountsCount){
- return 0;
- }
+ // Get the account refresh time.
+
+ if (AccountNum > AccountsCount){
+ return 0;
+ }
- return AccountRefresh[AccountNum];
+ return AccountRefresh[AccountNum];
}
\ No newline at end of file