X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcommon%2Fdefaults.cpp;h=924c550d55b7e4e85ecc0d781b5b65927a01213f;hb=ccc379ac30775d5b73698b83875a35fc1bfa56d0;hp=9fc5e4d4501c0b4085e4288cf3d842f7034df97a;hpb=87b1ab30b0f67dfa0457f9e946757d83cfb25106;p=xestiaab%2F.git
diff --git a/source/common/defaults.cpp b/source/common/defaults.cpp
index 9fc5e4d..924c550 100644
--- a/source/common/defaults.cpp
+++ b/source/common/defaults.cpp
@@ -16,208 +16,262 @@
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
-#include
-#include
+#include "defaults.h"
+
+using namespace std;
void SetupDefaultAddressBook(){
- // Check if the 'Default.local' directory exists.
-
- wxString DefaultLocalDir;
+ // Setup the default address book if there are none.
-#if defined(__HAIKU__)
+ // Check if the 'Default.local' directory exists.
- //preffilename = wxT("noo");
+ wxString DefaultLocalDir;
+#if defined(__HAIKU__)
+
#elif defined(__WIN32__)
- DefaultLocalDir.Clear();
- DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
- DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\accounts\\"));
- DefaultLocalDir.Append(wxT("Default.local"));
+ DefaultLocalDir.Clear();
+ DefaultLocalDir.Append(wxString::FromUTF8(getenv("APPDATA")));
+ DefaultLocalDir.Append(wxT("\\Xestia\\Address Book\\accounts\\"));
+ DefaultLocalDir.Append(wxT("Default.local"));
#elif defined(__APPLE__)
- DefaultLocalDir.Clear();
- DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Address Book/accounts/"));
- DefaultLocalDir.Append(wxT("Default.local"));
+ DefaultLocalDir.Clear();
+ DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultLocalDir.Append(wxT("/Library/Preferences/Xestia/Address Book/accounts/"));
+ DefaultLocalDir.Append(wxT("Default.local"));
#else
- DefaultLocalDir.Clear();
- DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
- DefaultLocalDir.Append(wxT("Default.local"));
+ DefaultLocalDir.Clear();
+ DefaultLocalDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultLocalDir.Append(wxT("/.xestiaab/accounts/"));
+ DefaultLocalDir.Append(wxT("Default.local"));
#endif
- if (wxDirExists(DefaultLocalDir) == FALSE){
+ if (wxDirExists(DefaultLocalDir) == FALSE){
- if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
+ if (wxMkdir(DefaultLocalDir, 0740) == TRUE){
- }
+ }
- }
+ }
}
void SetupDefaultSettings(){
- // Setup default (non account) settings if they don't exist.
+ // Setup the default settings if they don't exist.
+
+ // Setup default (non account) settings if they don't exist.
- wxString DefaultPrefDir;
+ wxString DefaultPrefDir;
#if defined(__HAIKU__)
- //preffilename = wxT("noo");
#elif defined(__WIN32__)
- DefaultPrefDir.Clear();
- DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
- DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
+ DefaultPrefDir.Clear();
+ DefaultPrefDir.Append(wxString::FromUTF8(getenv("APPDATA")));
+ DefaultPrefDir.Append(wxT("\\Xestia\\Address Book\\preferences\\"));
#elif defined(__APPLE__)
- DefaultPrefDir.Clear();
- DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences"));
+ DefaultPrefDir.Clear();
+ DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultPrefDir.Append(wxT("/Library/Preferences/Xestia/Address Book/preferences/"));
#else
- DefaultPrefDir.Clear();
- DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
+ DefaultPrefDir.Clear();
+ DefaultPrefDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultPrefDir.Append(wxT("/.xestiaab/preferences/"));
#endif
- // Create the accounts file if it doesn't exist.
+ // Create the accounts file if it doesn't exist.
- if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
+ if (wxFileExists(DefaultPrefDir + wxT("accounts")) == FALSE){
- wxString AccountsFilename;
- wxFFile AccountsFile;
+ wxString AccountsFilename;
+ wxFFile AccountsFile;
- AccountsFilename = DefaultPrefDir;
- AccountsFilename.Append(wxT("accounts"));
+ AccountsFilename = DefaultPrefDir;
+ AccountsFilename.Append(wxT("accounts"));
#if wxABI_VERSION < 20900
- AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
+ AccountsFile.Open(AccountsFilename.c_str(), wxT("w"));
#else
- AccountsFile.Open(AccountsFilename, wxT("w"));
+ AccountsFile.Open(AccountsFilename, wxT("w"));
#endif
- AccountsFile.Write(wxT(""));
+ AccountsFile.Write(wxT(""));
- }
+ }
- // Create the preferences file if it doesn't exist.
+ // Create the preferences file if it doesn't exist.
- if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
+ if (wxFileExists(DefaultPrefDir + wxT("settings")) == FALSE){
- wxString PrefsFilename;
- wxFFile PrefsFile;
+ wxString PrefsFilename;
+ wxFFile PrefsFile;
- PrefsFilename = DefaultPrefDir;
- PrefsFilename.Append(wxT("settings"));
+ PrefsFilename = DefaultPrefDir;
+ PrefsFilename.Append(wxT("settings"));
#if wxABI_VERSION < 20900
- PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
+ PrefsFile.Open(PrefsFilename.c_str(), wxT("w"));
#else
- PrefsFile.Open(PrefsFilename, wxT("w"));
+ PrefsFile.Open(PrefsFilename, wxT("w"));
#endif
- PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\n"));
+ PrefsFile.Write(wxT("HideLocalAddressBooks=false\nSaveWindowPosition=true\nUseBackgroundContactColour=false\n"));
- }
-
+ }
+
+ // Check if the default account is in the accounts list.
+ // Add it if it isn't.
+
+ wxString accountsConfigFile = DefaultPrefDir;
+ accountsConfigFile.Append(wxT("accounts"));
+
+ wxFileConfig *accountConfigData = new wxFileConfig("", "", accountsConfigFile);
+
+ long itemIndex = 0;
+ wxString accountName;
+ wxString accountType;
+ wxString accountDirectory;
+ bool continueProcessing = false;
+ bool defaultCalendarExists = false;
+
+ continueProcessing = accountConfigData->GetFirstGroup(accountName, itemIndex);
+
+ while (continueProcessing){
+
+ accountConfigData->SetPath(accountName);
+ accountConfigData->Read(wxT("type"), &accountType);
+ accountConfigData->Read(wxT("accountdir"), &accountDirectory);
+
+ if (accountType == wxT("Local") && accountDirectory == wxT("Default")){
+
+ defaultCalendarExists = true;
+
+ }
+
+ continueProcessing = accountConfigData->GetNextGroup(accountName, itemIndex);
+
+ }
+
+ if (defaultCalendarExists == false){
+
+ // Create the account in the accounts file.
+
+ accountConfigData->SetPath(wxT("/Default"));
+ accountConfigData->Write(wxT("type"), wxT("Local"));
+ accountConfigData->Write(wxT("accountdir"), wxT("Default"));
+ accountConfigData->Write(wxT("prefix"), wxT(""));
+ accountConfigData->Write(wxT("address"), wxT(""));
+ accountConfigData->Write(wxT("port"), wxT(""));
+ accountConfigData->Write(wxT("ssl"), wxT("false"));
+ accountConfigData->Write(wxT("username"), wxT(""));
+ accountConfigData->Write(wxT("password"), wxT(""));
+ accountConfigData->Write(wxT("prefix"), wxT(""));
+ accountConfigData->Write(wxT("refresh"), wxT("1800"));
+
+ }
+
+ delete accountConfigData;
+ accountConfigData = nullptr;
+
}
void SetupDirectories(){
- // Create the directories if they don't exist.
-
- wxString DefaultSettingsDir;
+ // Create the directories if they don't exist.
+ wxString DefaultSettingsDir;
+
#if defined(__HAIKU__)
- //preffilename = wxT("noo");
-
#elif defined(__WIN32__)
- DefaultSettingsDir.Clear();
- DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
- DefaultSettingsDir.Append(wxT("\\Xestia\\"));
+ DefaultSettingsDir.Clear();
+ DefaultSettingsDir.Append(wxString::FromUTF8(getenv("APPDATA")));
+ DefaultSettingsDir.Append(wxT("\\Xestia\\"));
- if (wxDirExists(DefaultSettingsDir) == FALSE){
+ if (wxDirExists(DefaultSettingsDir) == FALSE){
- // Create the directory.
+ // Create the directory.
- if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
+ if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
- }
+ }
- }
+ }
- // TODO: APPEND 'Address Book' to the directory.
+ // 'Address Book' to the directory.
- DefaultSettingsDir.Append(wxT("\\Address Book\\"));
+ DefaultSettingsDir.Append(wxT("\\Address Book\\"));
#elif defined(__APPLE__)
- DefaultSettingsDir.Clear();
- DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
+ DefaultSettingsDir.Clear();
+ DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultSettingsDir.Append(wxT("/Library/Preferences/Xestia/"));
- if (wxDirExists(DefaultSettingsDir) == FALSE){
+ if (wxDirExists(DefaultSettingsDir) == FALSE){
- // Create the directory.
+ // Create the directory.
- if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
+ if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
- }
+ }
- }
+ }
- // TODO: APPEND 'Address Book' to the directory.
+ // Append 'Address Book' to the directory.
- DefaultSettingsDir.Append(wxT("/Address Book/"));
+ DefaultSettingsDir.Append(wxT("/Address Book/"));
#else
- DefaultSettingsDir.Clear();
- DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
- DefaultSettingsDir.Append(wxT("/.xestiaab/"));
+ DefaultSettingsDir.Clear();
+ DefaultSettingsDir.Append(wxString::FromUTF8(getenv("HOME")));
+ DefaultSettingsDir.Append(wxT("/.xestiaab/"));
#endif
- // Check if the directory exists.
+ // Check if the directory exists.
- if (wxDirExists(DefaultSettingsDir) == FALSE){
+ if (wxDirExists(DefaultSettingsDir) == FALSE){
- // Create the directory.
+ // Create the directory.
- if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
+ if (wxMkdir(DefaultSettingsDir, 0740) == TRUE){
- }
+ }
- }
+ }
- if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
+ if (wxDirExists(DefaultSettingsDir + wxT("accounts")) == FALSE){
- if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){
+ if (wxMkdir(DefaultSettingsDir + wxT("accounts"), 0740) == TRUE){
- }
+ }
- }
+ }
- if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
+ if (wxDirExists(DefaultSettingsDir + wxT("preferences")) == FALSE){
- if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){
+ if (wxMkdir(DefaultSettingsDir + wxT("preferences"), 0740) == TRUE){
- }
+ }
- }
+ }
}
\ No newline at end of file