diff --git a/application/ImageCache.h b/application/ImageCache.h index 2496571..1b59d00 100644 --- a/application/ImageCache.h +++ b/application/ImageCache.h @@ -14,7 +14,8 @@ class BBitmap; #include #include -#include "KeyMap.h" + +#include class ImageCache { diff --git a/application/ProtocolManager.h b/application/ProtocolManager.h index 1a00016..24f0fe8 100644 --- a/application/ProtocolManager.h +++ b/application/ProtocolManager.h @@ -9,7 +9,8 @@ #include #include -#include "KeyMap.h" +#include + #include "CayaProtocol.h" class BBitmap; diff --git a/application/ProtocolSettings.cpp b/application/ProtocolSettings.cpp index 1a7c79f..9fa7d90 100644 --- a/application/ProtocolSettings.cpp +++ b/application/ProtocolSettings.cpp @@ -44,8 +44,7 @@ const float kDividerWidth = 1.0f; ProtocolSettings::ProtocolSettings(CayaProtocol* cayap) : fProtocol(cayap), - fTemplate(new BMessage()), - fSettings(new BMessage()) + fTemplate(new BMessage()) { _Init(); } @@ -54,7 +53,6 @@ ProtocolSettings::ProtocolSettings(CayaProtocol* cayap) ProtocolSettings::~ProtocolSettings() { delete fTemplate; - delete fSettings; } @@ -65,19 +63,27 @@ ProtocolSettings::InitCheck() const } -BList* +CayaProtocol* +ProtocolSettings::Protocol() const +{ + return fProtocol; +} + + +List ProtocolSettings::Accounts() const { + List list; + BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - return NULL; + return list; path.Append("Caya/Protocols"); path.Append(fProtocol->GetSignature()); if (create_directory(path.Path(), 0755) != B_OK) - return NULL; + return list; - BList* list = new BList(); BDirectory dir(path.Path()); BEntry entry; while (dir.GetNextEntry(&entry) == B_OK) { @@ -86,10 +92,8 @@ ProtocolSettings::Accounts() const if (msg.Unflatten(&file) == B_OK) { char buffer[B_PATH_NAME_LENGTH]; - if (entry.GetName(buffer) == B_OK) { - BString* string = new BString(buffer); - list->AddItem(string); - } + if (entry.GetName(buffer) == B_OK) + list.AddItem(BString(buffer)); } } @@ -98,85 +102,26 @@ ProtocolSettings::Accounts() const status_t -ProtocolSettings::Load(const char* account) +ProtocolSettings::LoadTemplate(BView* parent) { - status_t ret = B_ERROR; - - // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) - return ret; - - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) - return ret; - - // Load settings file - path.Append(account); - BFile file(path.Path(), B_READ_ONLY); - return fSettings->Unflatten(&file); + return Load(NULL, parent); } status_t -ProtocolSettings::Save(const char* account) -{ - status_t ret = B_ERROR; - - // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) - return ret; - - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) - return ret; - - // Load settings file - path.Append(account); - BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); - return fSettings->Flatten(&file); -} - - -status_t -ProtocolSettings::Delete(const char* account) -{ - status_t ret = B_ERROR; - - // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) - return ret; - - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) - return ret; - path.Append(account); - - // Delete settings file - BEntry entry(path.Path()); - if ((ret = entry.Remove()) != B_OK) - return ret; - - delete fSettings; - fSettings = new BMessage(); - return B_OK; -} - - -void -ProtocolSettings::BuildGUI(BView* parent) +ProtocolSettings::Load(const char* account, BView* parent) { if (!parent) debugger("Couldn't build protocol's settings GUI on a NULL parent!"); + BMessage* settings = NULL; + + if (account) { + status_t ret = _Load(account, &settings); + if (ret != B_OK) + return ret; + } + BMessage curr; float inset = ceilf(be_plain_font->Size() * 0.7f); @@ -215,17 +160,21 @@ ProtocolSettings::BuildGUI(BView* parent) menu->AddItem(item); } - value = fSettings->FindString(name); - if (value) - menu->FindItem(value)->SetMarked(true); + if (settings) { + value = settings->FindString(name); + if (value) + menu->FindItem(value)->SetMarked(true); + } } else { // It's a free-text setting if (curr.FindBool("multi_line", &multiLine) != B_OK) multiLine = false; - value = fSettings->FindString(name); - if (!value) - value = curr.FindString("default"); + if (settings) { + value = settings->FindString(name); + if (!value) + value = curr.FindString("default"); + } if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; @@ -240,7 +189,10 @@ ProtocolSettings::BuildGUI(BView* parent) menu = new BPopUpMenu(name); int32 def = 0; - status_t hasValue = fSettings->FindInt32(name, 0, &def); + status_t hasValue = B_ERROR; + + if (settings) + settings->FindInt32(name, 0, &def); if (hasValue != B_OK) hasValue = curr.FindInt32("default", 0, &def); @@ -262,7 +214,7 @@ ProtocolSettings::BuildGUI(BView* parent) // It's a free-text (but number) setting int32 v = 0; - if (fSettings->FindInt32(name, &v) == B_OK) { + if (settings && settings->FindInt32(name, &v) == B_OK) { sprintf(temp,"%ld", v); value = temp; } else if (curr.FindInt32("default", &v) == B_OK) { @@ -278,7 +230,7 @@ ProtocolSettings::BuildGUI(BView* parent) case B_BOOL_TYPE: { bool active; - if (fSettings->FindBool(name, &active) != B_OK) { + if (settings && settings->FindBool(name, &active) != B_OK) { if (curr.FindBool("default", &active) != B_OK) active = false; } @@ -329,15 +281,19 @@ ProtocolSettings::BuildGUI(BView* parent) layout.AddGlue(); parent->AddChild(layout); + + return B_OK; } status_t -ProtocolSettings::SaveGUI(BView* parent) +ProtocolSettings::Save(const char* account, BView* parent) { if (!parent) debugger("Couldn't save protocol's settings GUI on a NULL parent!"); + BMessage* settings = new BMessage(); + BMessage cur; for (int32 i = 0; fTemplate->FindMessage("setting", i, &cur) == B_OK; i++) { const char* name = cur.FindString("name"); @@ -359,10 +315,10 @@ ProtocolSettings::SaveGUI(BView* parent) if (textControl) { switch (type) { case B_STRING_TYPE: - fSettings->AddString(name, textControl->Text()); + settings->AddString(name, textControl->Text()); break; case B_INT32_TYPE: - fSettings->AddInt32(name, atoi(textControl->Text())); + settings->AddInt32(name, atoi(textControl->Text())); break; default: return B_ERROR; @@ -378,10 +334,10 @@ ProtocolSettings::SaveGUI(BView* parent) switch (type) { case B_STRING_TYPE: - fSettings->AddString(name, item->Label()); + settings->AddString(name, item->Label()); break; case B_INT32_TYPE: - fSettings->AddInt32(name, atoi(item->Label())); + settings->AddInt32(name, atoi(item->Label())); break; default: return B_ERROR; @@ -391,15 +347,40 @@ ProtocolSettings::SaveGUI(BView* parent) BCheckBox* checkBox = dynamic_cast(view); if (checkBox) - fSettings->AddBool(name, (checkBox->Value() == B_CONTROL_ON)); + settings->AddBool(name, (checkBox->Value() == B_CONTROL_ON)); NotifyingTextView* textView = dynamic_cast(view); if (textView) - fSettings->AddString(name, textView->Text()); + settings->AddString(name, textView->Text()); } -fSettings->PrintToStream(); + return _Save(account, settings); +} + + +status_t +ProtocolSettings::Delete(const char* account) +{ + status_t ret = B_ERROR; + + // Find user's settings path + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) + return ret; + + // Create path + path.Append("Caya/Protocols"); + path.Append(fProtocol->GetSignature()); + if ((ret = create_directory(path.Path(), 0755)) != B_OK) + return ret; + path.Append(account); + + // Delete settings file + BEntry entry(path.Path()); + if ((ret = entry.Remove()) != B_OK) + return ret; + return B_OK; } @@ -433,3 +414,60 @@ ProtocolSettings::_Init() // Load protocol's settings template fTemplate->Unflatten((const char*)data); } + + +status_t +ProtocolSettings::_Load(const char* account, BMessage** settings) +{ + *settings = NULL; + + if (!account || !settings) + return B_BAD_VALUE; + + status_t ret = B_ERROR; + + // Find user's settings path + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) + return ret; + + // Create path + path.Append("Caya/Protocols"); + path.Append(fProtocol->GetSignature()); + if ((ret = create_directory(path.Path(), 0755)) != B_OK) + return ret; + + // Load settings file + path.Append(account); + BFile file(path.Path(), B_READ_ONLY); + BMessage* msg = new BMessage(); + ret = msg->Unflatten(&file); + *settings = msg; + return ret; +} + + +status_t +ProtocolSettings::_Save(const char* account, BMessage* settings) +{ + if (!account || !settings) + return B_BAD_VALUE; + + status_t ret = B_ERROR; + + // Find user's settings path + BPath path; + if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) + return ret; + + // Create path + path.Append("Caya/Protocols"); + path.Append(fProtocol->GetSignature()); + if ((ret = create_directory(path.Path(), 0755)) != B_OK) + return ret; + + // Load settings file + path.Append(account); + BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); + return settings->Flatten(&file); +} diff --git a/application/ProtocolSettings.h b/application/ProtocolSettings.h index 28d7426..7a2b347 100644 --- a/application/ProtocolSettings.h +++ b/application/ProtocolSettings.h @@ -6,33 +6,35 @@ #ifndef _PROTOCOL_SETTINGS_H #define _PROTOCOL_SETTINGS_H +#include + class BMessage; class CayaProtocol; class ProtocolSettings { public: - ProtocolSettings(CayaProtocol* cayap); - ~ProtocolSettings(); + ProtocolSettings(CayaProtocol* cayap); + ~ProtocolSettings(); - status_t InitCheck() const; + status_t InitCheck() const; - BList* Accounts() const; + CayaProtocol* Protocol() const; + List Accounts() const; - status_t Load(const char* account); - status_t Save(const char* account); - status_t Delete(const char* account); - - void BuildGUI(BView* parent); - status_t SaveGUI(BView* parent); + status_t LoadTemplate(BView* parent); + status_t Load(const char* account, BView* parent); + status_t Save(const char* account, BView* parent); + status_t Delete(const char* account); private: - status_t fStatus; - CayaProtocol* fProtocol; - BString fAccount; - BMessage* fTemplate; - BMessage* fSettings; + status_t fStatus; + CayaProtocol* fProtocol; + BString fAccount; + BMessage* fTemplate; - void _Init(); + void _Init(); + status_t _Load(const char* account, BMessage** settings); + status_t _Save(const char* account, BMessage* settings); }; #endif // _PROTOCOL_SETTINGS_H diff --git a/application/Server.h b/application/Server.h index ca96919..0b43731 100644 --- a/application/Server.h +++ b/application/Server.h @@ -8,9 +8,10 @@ #include #include +#include + #include "CayaConstants.h" #include "ContactLinker.h" -#include "KeyMap.h" class MainWindow; class RosterItem; diff --git a/application/preferences/AccountListItem.cpp b/application/preferences/AccountListItem.cpp index 7b3641f..897f79d 100644 --- a/application/preferences/AccountListItem.cpp +++ b/application/preferences/AccountListItem.cpp @@ -20,7 +20,6 @@ AccountListItem::AccountListItem(CayaProtocol* cayap, const char* account) fBaselineOffset(0) { fSettings = new ProtocolSettings(cayap); - fSettings->Load(account); } diff --git a/application/preferences/PreferencesAccounts.cpp b/application/preferences/PreferencesAccounts.cpp index 5312bef..41a2285 100644 --- a/application/preferences/PreferencesAccounts.cpp +++ b/application/preferences/PreferencesAccounts.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,6 +21,7 @@ #include #include #include +#include #include "AccountListItem.h" #include "CayaProtocol.h" @@ -28,14 +29,15 @@ #include "ProtocolManager.h" #include "ProtocolSettings.h" -const uint32 kAddAccount = 'ADAC'; -const uint32 kEditAccount = 'EDAC'; -const uint32 kDelAccount = 'DLAC'; -const uint32 kSelect = 'SELT'; +const uint32 kAddAccount = 'ADAC'; +const uint32 kEditAccount = 'EDAC'; +const uint32 kDelAccount = 'DLAC'; +const uint32 kSelect = 'SELT'; -const uint32 kCancel = 'CANC'; -const uint32 kOK = 'SAVE'; -const uint32 kChanged = 'CHGD'; +const uint32 kCancel = 'CANC'; +const uint32 kOK = 'SAVE'; + +const uint32 kChanged = 'CHGD'; class AccountView : public BView { @@ -100,21 +102,22 @@ public: B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) { fSettings = new ProtocolSettings(cayap); - if (account) - fSettings->Load(account); fAccountName = new BTextControl("accountName", "Account name:", NULL, NULL); fAccountName->SetFont(be_bold_font); - fAccountName->MakeFocus(); if (account) { fAccountName->SetText(account); fAccountName->SetEnabled(false); - } + } else + fAccountName->MakeFocus(true); Divider* divider = new Divider("divider", B_WILL_DRAW); fTop = new AccountView("top"); - fSettings->BuildGUI(fTop); + if (account) + fSettings->Load(account, fTop); + else + fSettings->LoadTemplate(fTop); BButton* cancel = new BButton("Cancel", new BMessage(kCancel)); BButton* ok = new BButton("OK", new BMessage(kOK)); @@ -142,9 +145,8 @@ public: { switch (msg->what) { case kOK: - if (fSettings->SaveGUI(fTop) == B_OK) - if (fSettings->Save(fAccountName->Text()) == B_OK) - Close(); + if (fSettings->Save(fAccountName->Text(), fTop) == B_OK) + Close(); // TODO: Error! break; case kCancel: @@ -177,20 +179,14 @@ PreferencesAccounts::PreferencesAccounts() BList* protocols = ProtocolManager::Get()->GetProtocols(); - fProtosMenu = new BMenu("Add"); + fProtosMenu = new BPopUpMenu(NULL, true); for (int32 i = 0; i < protocols->CountItems(); i++) { CayaProtocol* cayap = reinterpret_cast(protocols->ItemAtFast(i)); ProtocolSettings* settings = new ProtocolSettings(cayap); - BList* accounts = settings->Accounts(); // Add accounts to list view - for (int32 j = 0; j < accounts->CountItems(); j++) { - BString* account = reinterpret_cast(accounts->ItemAtFast(j)); - AccountListItem* listItem = new AccountListItem(cayap, - account->String()); - fListView->AddItem(listItem); - } + _LoadListView(settings); // Add menu items BMessage* msg = new BMessage(kAddAccount); @@ -201,13 +197,13 @@ PreferencesAccounts::PreferencesAccounts() ProtocolManager::Get()->GetProtocolIcon(cayap->GetSignature())); fProtosMenu->AddItem(item); - delete accounts; delete settings; } - BMenuField* proto = new BMenuField("addAccountField", NULL, fProtosMenu); - fDelButton = new BButton(" - ", new BMessage(kDelAccount)); - fEditButton = new BButton("Edit...", new BMessage(kEditAccount)); + ToolButton* proto = new ToolButton("+", NULL); + proto->SetMenu(fProtosMenu); + fDelButton = new ToolButton("-", new BMessage(kDelAccount)); + fEditButton = new ToolButton("Edit...", new BMessage(kEditAccount)); fDelButton->SetEnabled(false); fEditButton->SetEnabled(false); @@ -255,6 +251,9 @@ PreferencesAccounts::MessageReceived(BMessage* msg) if (msg->FindPointer("protocol", &protocol) == B_OK) { CayaProtocol* cayap = (CayaProtocol*) protocol; + BLooper* looper = new BLooper(); + looper->AddHandler(this); + AccountDialog* dialog = new AccountDialog("Add account", cayap); dialog->Show(); } @@ -272,6 +271,9 @@ PreferencesAccounts::MessageReceived(BMessage* msg) CayaProtocol* cayap = item->Protocol(); const char* account = item->Account(); + BLooper* looper = new BLooper(); + looper->AddHandler(this); + AccountDialog* dialog = new AccountDialog("Edit account", cayap, account); dialog->Show(); } @@ -298,3 +300,21 @@ PreferencesAccounts::MessageReceived(BMessage* msg) BView::MessageReceived(msg); } } + + +void +PreferencesAccounts::_LoadListView(ProtocolSettings* settings) +{ + if (!settings) + return; + + List accounts = settings->Accounts(); + + // Add accounts to list view + for (uint32 i = 0; i < accounts.CountItems(); i++) { + BString account = accounts.ItemAt(i); + AccountListItem* listItem = new AccountListItem( + settings->Protocol(), account.String()); + fListView->AddItem(listItem); + } +} diff --git a/application/preferences/PreferencesAccounts.h b/application/preferences/PreferencesAccounts.h index 04f5a05..8ff9c55 100644 --- a/application/preferences/PreferencesAccounts.h +++ b/application/preferences/PreferencesAccounts.h @@ -7,9 +7,12 @@ #include -class BListView; -class BMenu; class BButton; +class BListView; +class BPopUpMenu; + +class ToolButton; +class ProtocolSettings; class PreferencesAccounts : public BView { public: @@ -20,9 +23,12 @@ public: private: BListView* fListView; - BMenu* fProtosMenu; - BButton* fDelButton; - BButton* fEditButton; + BPopUpMenu* fProtosMenu; + ToolButton* fDelButton; + ToolButton* fEditButton; + + + void _LoadListView(ProtocolSettings* settings); }; #endif // _PREFERENCES_ACCOUNTS_H diff --git a/libs/libinterface/ToolButton.cpp b/libs/libinterface/ToolButton.cpp index f9a8c8e..f885703 100644 --- a/libs/libinterface/ToolButton.cpp +++ b/libs/libinterface/ToolButton.cpp @@ -300,6 +300,30 @@ ToolButton::Perform(perform_code code, void* data) ((perform_data_preferred_size*)data)->return_value = ToolButton::PreferredSize(); return B_OK; + case PERFORM_CODE_LAYOUT_ALIGNMENT: + ((perform_data_layout_alignment*)data)->return_value + = ToolButton::LayoutAlignment(); + return B_OK; + case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH: + ((perform_data_has_height_for_width*)data)->return_value + = ToolButton::HasHeightForWidth(); + return B_OK; + case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH: { + perform_data_get_height_for_width* _data + = (perform_data_get_height_for_width*)data; + ToolButton::GetHeightForWidth(_data->width, &_data->min, &_data->max, + &_data->preferred); + return B_OK; + } + case PERFORM_CODE_INVALIDATE_LAYOUT: { + perform_data_invalidate_layout* _data + = (perform_data_invalidate_layout*)_data; + ToolButton::InvalidateLayout(_data->descendants); + return B_OK; + } + case PERFORM_CODE_DO_LAYOUT: + ToolButton::DoLayout(); + return B_OK; } return BControl::Perform(code, data); @@ -375,7 +399,7 @@ ToolButton::_ValidatePreferredSize() GetFontHeight(&fontHeight); fPreferredSize.height - = ceilf((fontHeight.ascent + fontHeight.descent) * 1.8) + = ceilf((fontHeight.ascent + fontHeight.descent) * 1.5) + (fBitmap ? kToolbarIconSize + 4.0f : 0); ResetLayoutInvalidation();