diff --git a/engine/Client.cpp b/engine/Client.cpp index f2fdf3bf..ffe068c2 100644 --- a/engine/Client.cpp +++ b/engine/Client.cpp @@ -140,6 +140,11 @@ void Window::title(const String& text) m_title = text; } +void Window::context(const String& text) +{ + m_context = text; +} + bool Window::related(const Window* wnd) const { if ((wnd == this) || !wnd || wnd->master()) @@ -157,6 +162,8 @@ bool Window::setParams(const NamedList& params) String n(s->name()); if (n == "title") title(*s); + if (n == "context") + context(*s); else if (n.startSkip("show:",false)) ok = setShow(n,s->toBoolean()) && ok; else if (n.startSkip("active:",false)) @@ -363,7 +370,9 @@ Client* Client::s_client = 0; int Client::s_changing = 0; static Configuration s_accounts; static Configuration s_contacts; +static Configuration s_providers; +// Parameters that are stored with account static const char* s_accParams[] = { "username", "password", @@ -373,6 +382,14 @@ static const char* s_accParams[] = { 0 }; +// Parameters that are applied from provider template +static const char* s_provParams[] = { + "server", + "domain", + "outbound", + 0 +}; + Client::Client(const char *name) : Thread(name), m_initialized(false), m_line(0), m_oneThread(true), @@ -495,6 +512,17 @@ void Client::initClient() } } + s_providers = Engine::configFile("providers"); + s_providers.load(); + n = s_providers.sections(); + for (i=0; igetBoolValue("enabled",true)) { + if (!hasOption("acc_providers",*sect)) + addOption("acc_providers",*sect,false); + } + } + bool tmp = getWindow("channels") || hasElement("channels") || getWindow("lines") || hasElement("lines"); @@ -527,6 +555,7 @@ bool Client::openPopup(const String& name, const NamedList* params, const Window Window* wnd = getWindow(name); if (!wnd) return false; + wnd->context(""); if (params) wnd->setParams(*params); if (parent) @@ -970,9 +999,8 @@ bool Client::action(Window* wnd, const String& name) // accounts window actions else if (name == "acc_new") { NamedList params(""); - params.setParam("select:acc_provider","--"); + params.setParam("select:acc_providers","--"); params.setParam("acc_account",""); - params.setParam("acc_account_orig",""); params.setParam("acc_username",""); params.setParam("acc_password",""); params.setParam("acc_server",""); @@ -986,9 +1014,9 @@ bool Client::action(Window* wnd, const String& name) String acc; if (getSelect("accounts",acc,wnd)) { NamedList params(""); - params.setParam("select:acc_provider","--"); + params.setParam("context",acc); + params.setParam("select:acc_providers","--"); params.setParam("acc_account",acc); - params.setParam("acc_account_orig",acc); NamedList* sect = s_accounts.getSection(acc); if (sect) { params.setParam("select:acc_protocol",sect->getValue("protocol")); @@ -1030,11 +1058,10 @@ bool Client::action(Window* wnd, const String& name) return false; } // check if the account name has changed, delete old if so - String oldAcc; - if (getText("acc_account_orig",oldAcc,wnd) && oldAcc && (oldAcc != newAcc)) { - s_accounts.clearSection(oldAcc); + if (wnd && wnd->context() && (wnd->context() != newAcc)) { + s_accounts.clearSection(wnd->context()); Message* m = new Message("user.login"); - m->addParam("account",oldAcc); + m->addParam("account",wnd->context()); m->addParam("operation","delete"); Engine::enqueue(m); } @@ -1067,7 +1094,6 @@ bool Client::action(Window* wnd, const String& name) else if (name == "abk_new") { NamedList params(""); params.setParam("abk_contact",""); - params.setParam("abk_contact_orig",""); params.setParam("abk_number",""); params.setParam("modal",String::boolText(true)); if (openPopup("addrbook",¶ms,wnd)) @@ -1077,8 +1103,8 @@ bool Client::action(Window* wnd, const String& name) String cnt; if (getSelect("contacts",cnt,wnd)) { NamedList params(""); - params.setParam("abk_contact_orig",cnt); params.setParam("abk_contact",cnt); + params.setParam("context",cnt); params.setParam("modal",String::boolText(true)); if (openPopup("addrbook",¶ms,wnd)) return true; @@ -1196,13 +1222,23 @@ bool Client::select(Window* wnd, const String& name, const String& item, const S if (setSelect("account","") || setSelect("account","--")) return true; } - else if (name == "acc_provider") { + else if (name == "acc_providers") { // apply provider template if (checkDashes(item)) return true; // reset selection after we apply it - if (setSelect(name,"") || setSelect(name,"--")) - return true; + if (!setSelect(name,"")) + setSelect(name,"--"); + NamedList* sect = s_providers.getSection(item); + if (!sect) + return false; + setSelect("acc_protocol",sect->getValue("protocol")); + for (const char** par = s_provParams; *par; par++) { + String name; + name << "acc_" << *par; + setText(name,sect->getValue(*par)); + } + return true; } // unknown/unhandled - generate a message for them diff --git a/modules/skin/tabbed/gtk2client.ui b/modules/skin/tabbed/gtk2client.ui index e85ff02e..2497e3ea 100644 --- a/modules/skin/tabbed/gtk2client.ui +++ b/modules/skin/tabbed/gtk2client.ui @@ -306,7 +306,7 @@ vbox=> hbox=> vbox=0,2,,,> label=Use provider settings - option=,,,,acc_provider,--,FWD + option=,,,,acc_providers,-- tooltip=Apply template settings for this provider label=Account name editor=,,,,acc_account, diff --git a/yatecbase.h b/yatecbase.h index a34f7cdb..67e7a15b 100644 --- a/yatecbase.h +++ b/yatecbase.h @@ -49,22 +49,129 @@ class YATE_API Window : public GenObject { friend class Client; public: + /** + * Constructor, creates a new windows with an ID + * @param id String identifier of the new window + */ Window(const char* id = 0); + + /** + * Destructor + */ virtual ~Window(); + + /** + * Retrive the standard name of this Window, used to search in lists + * @return Identifier of this window + */ virtual const String& toString() const; + + /* + * Get the window's title (may not be displayed on screen) + * @return Title of this window + */ virtual void title(const String& text); + + /** + * Get the contextual information previously associated with this window + * @return String contextual information + */ + virtual void context(const String& text); + + /** + * Set window parameters or widget contents + * @param params List of parameters to set in the window and its widgets + * @return True if all parameters could be set + */ virtual bool setParams(const NamedList& params); + + /** + * Force this window on top of another one which becomes its parent + * @param parent Window to force as parent of this one + */ virtual void setOver(const Window* parent) = 0; + + /** + * Check if this window has an element by name + * @param name Name of the element to search for + * @return True if one element with the given name exists + */ virtual bool hasElement(const String& name) = 0; + + /** + * Set an element as interactive in the window + * @param name Name of the element + * @param active True to make interactive, false to disallow interaction + * @return True if the operation was successfull + */ virtual bool setActive(const String& name, bool active) = 0; + + /** + * Set the visibility of an element in the window + * @param name Name of the element + * @param visible True to make element visible, false to hide it + * @return True if the operation was successfull + */ virtual bool setShow(const String& name, bool visible) = 0; + + /** + * Set the displayed text of an element in the window + * @param name Name of the element + * @param text Text value to set in the element + * @return True if the operation was successfull + */ virtual bool setText(const String& name, const String& text) = 0; + + /** + * Set the checked or toggled status of an element in the window + * @param name Name of the element + * @param checked True to make element checked or toggled + * @return True if the operation was successfull + */ virtual bool setCheck(const String& name, bool checked) = 0; + + /** + * Set the selection of an item in an element in the window + * @param name Name of the element + * @param item Name of the item that should be selected + * @return True if the operation was successfull + */ virtual bool setSelect(const String& name, const String& item) = 0; + + /** + * Flag an element as requiring immediate attention + * @param name Name of the element + * @param urgent True if the element requires immediate attention + * @return True if the operation was successfull + */ virtual bool setUrgent(const String& name, bool urgent) = 0; + + /** + * Check if an element has an item by its name + * @param name Name of the element to search for + * @param item Name of the item that should be searched + * @return True if one item with the given name exists in the element + */ virtual bool hasOption(const String& name, const String& item) = 0; + + /** + * Add an item to an element that supports such an operation (list) + * @param name Name of the element + * @param item Name of the item to add + * @param atStart True to insert item on the first position, false to append + * @param text Displayed text to associate with the item (not all lists support it) + * @return True if the operation was successfull + */ virtual bool addOption(const String& name, const String& item, bool atStart = false, const String& text = String::empty()) = 0; + + /** + * Remove an item from an element (list) + * @param name Name of the element + * @param item Name of the item to remove + * @return True if the operation was successfull + */ virtual bool delOption(const String& name, const String& item) = 0; + virtual bool addTableRow(const String& name, const String& item, const NamedList* data = 0, bool atStart = false); virtual bool delTableRow(const String& name, const String& item); virtual bool setTableRow(const String& name, const String& item, const NamedList* data); @@ -82,21 +189,60 @@ public: virtual void moveRel(int dx, int dy) = 0; virtual bool related(const Window* wnd) const; virtual void menu(int x, int y) = 0; + + /** + * Retrive the standard name of this Window + * @return Identifier of this window + */ inline const String& id() const { return m_id; } + + /* + * Get the window's title (may not be displayed on screen) + * @return Title of this window + */ inline const String& title() const { return m_title; } + + /** + * Get the contextual information previously associated with this window + * @return String contextual information + */ + inline const String& context() const + { return m_context; } + + /** + * Get the visibility status of this window + * @return True if window is visible, false if it's hidden + */ inline bool visible() const { return m_visible; } + + /** + * Set the visibility status of this window + * @param yes True if window should be visible + */ inline void visible(bool yes) { if (yes) show(); else hide(); } + + /** + * Check if this window is a master (topmost) window + * @return True if this window is topmost + */ inline bool master() const { return m_master; } + + /** + * Check if this window is a popup window + * @return True if this window is initially hidden + */ inline bool popup() const { return m_popup; } + protected: String m_id; String m_title; + String m_context; bool m_visible; bool m_master; bool m_popup;