00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __YATECBASE_H
00026 #define __YATECBASE_H
00027
00028 #ifndef __cplusplus
00029 #error C++ is required
00030 #endif
00031
00032 #include <yatephone.h>
00033
00037 namespace TelEngine {
00038
00039 class Window;
00040 class UIWidget;
00041 class UIFactory;
00042 class Client;
00043 class ClientChannel;
00044 class ClientDriver;
00045 class ClientLogic;
00046 class DefaultLogic;
00047 class ClientWizard;
00048 class ClientAccount;
00049 class ClientAccountList;
00050 class ClientContact;
00051 class ClientResource;
00052 class MucRoomMember;
00053 class MucRoom;
00054 class DurationUpdate;
00055 class ClientSound;
00056
00057
00063 class YATE_API Window : public GenObject
00064 {
00065 friend class Client;
00066 YNOCOPY(Window);
00067 public:
00072 explicit Window(const char* id = 0);
00073
00077 virtual ~Window();
00078
00083 virtual const String& toString() const;
00084
00085
00086
00087
00088
00089 virtual void title(const String& text);
00090
00095 virtual void context(const String& text);
00096
00102 virtual bool setParams(const NamedList& params);
00103
00108 virtual void setOver(const Window* parent) = 0;
00109
00115 virtual bool hasElement(const String& name) = 0;
00116
00123 virtual bool setActive(const String& name, bool active) = 0;
00124
00131 virtual bool setFocus(const String& name, bool select = false) = 0;
00132
00139 virtual bool setShow(const String& name, bool visible) = 0;
00140
00148 virtual bool setText(const String& name, const String& text,
00149 bool richText = false) = 0;
00150
00157 virtual bool setCheck(const String& name, bool checked) = 0;
00158
00165 virtual bool setSelect(const String& name, const String& item) = 0;
00166
00173 virtual bool setUrgent(const String& name, bool urgent) = 0;
00174
00181 virtual bool hasOption(const String& name, const String& item) = 0;
00182
00191 virtual bool addOption(const String& name, const String& item, bool atStart = false,
00192 const String& text = String::empty()) = 0;
00193
00200 virtual bool getOptions(const String& name, NamedList* items) = 0;
00201
00208 virtual bool delOption(const String& name, const String& item) = 0;
00209
00218 virtual bool addLines(const String& name, const NamedList* lines, unsigned int max,
00219 bool atStart = false);
00220
00229 virtual bool addTableRow(const String& name, const String& item,
00230 const NamedList* data = 0, bool atStart = false);
00231
00239 virtual bool setMultipleRows(const String& name, const NamedList& data, const String& prefix = String::empty());
00240
00249 virtual bool insertTableRow(const String& name, const String& item,
00250 const String& before, const NamedList* data = 0);
00251
00258 virtual bool delTableRow(const String& name, const String& item);
00259
00267 virtual bool setTableRow(const String& name, const String& item, const NamedList* data);
00268
00277 virtual bool updateTableRow(const String& name, const String& item,
00278 const NamedList* data = 0, bool atStart = false);
00279
00291 virtual bool updateTableRows(const String& name, const NamedList* data,
00292 bool atStart = false);
00293
00301 virtual bool getTableRow(const String& name, const String& item, NamedList* data = 0);
00302
00308 virtual bool clearTable(const String& name);
00309
00317 virtual bool getText(const String& name, String& text, bool richText = false) = 0;
00318
00325 virtual bool getCheck(const String& name, bool& checked) = 0;
00326
00333 virtual bool getSelect(const String& name, String& item) = 0;
00334
00341 virtual bool buildMenu(const NamedList& params) = 0;
00342
00349 virtual bool removeMenu(const NamedList& params) = 0;
00350
00357 virtual bool setImage(const String& name, const String& image) = 0;
00358
00366 virtual bool setProperty(const String& name, const String& item, const String& value)
00367 { return false; }
00368
00376 virtual bool getProperty(const String& name, const String& item, String& value)
00377 { return false; }
00378
00382 inline void populate() {
00383 if (m_populated)
00384 return;
00385 doPopulate();
00386 m_populated = true;
00387 }
00388
00392 inline void init() {
00393 if (m_initialized)
00394 return;
00395 doInit();
00396 m_initialized = true;
00397 }
00398
00402 virtual void show() = 0;
00403
00407 virtual void hide() = 0;
00408
00414 virtual void size(int width, int height) = 0;
00415
00421 virtual void move(int x, int y) = 0;
00422
00428 virtual void moveRel(int dx, int dy) = 0;
00429
00435 virtual bool related(const Window* wnd) const;
00436
00437 virtual void menu(int x, int y) = 0;
00438
00443 virtual bool canClose()
00444 { return true; }
00445
00450 inline const String& id() const
00451 { return m_id; }
00452
00453
00454
00455
00456
00457 inline const String& title() const
00458 { return m_title; }
00459
00464 inline const String& context() const
00465 { return m_context; }
00466
00471 inline bool visible() const
00472 { return m_visible; }
00473
00478 inline void visible(bool yes)
00479 { if (yes) show(); else hide(); }
00480
00485 inline bool active() const
00486 { return m_active; }
00487
00492 inline bool master() const
00493 { return m_master; }
00494
00499 inline bool popup() const
00500 { return m_popup; }
00501
00510 virtual bool createDialog(const String& name, const String& title,
00511 const String& alias = String::empty(), const NamedList* params = 0) = 0;
00512
00518 virtual bool closeDialog(const String& name) = 0;
00519
00526 static bool isValidParamPrefix(const String& prefix);
00527
00528 protected:
00529 virtual void doPopulate() = 0;
00530 virtual void doInit() = 0;
00531
00532 String m_id;
00533 String m_title;
00534 String m_context;
00535 bool m_visible;
00536 bool m_active;
00537 bool m_master;
00538 bool m_popup;
00539 bool m_saveOnClose;
00540
00541 private:
00542 bool m_populated;
00543 bool m_initialized;
00544 };
00545
00546 class YATE_API UIWidget : public String
00547 {
00548 YNOCOPY(UIWidget);
00549 public:
00554 inline explicit UIWidget(const char* name = 0)
00555 : String(name)
00556 { }
00557
00561 virtual ~UIWidget()
00562 { }
00563
00568 inline const String& name() const
00569 { return toString(); }
00570
00576 virtual bool setParams(const NamedList& params)
00577 { return false; }
00578
00584 virtual bool getOptions(NamedList& items)
00585 { return false; }
00586
00594 virtual bool addTableRow(const String& item, const NamedList* data = 0,
00595 bool atStart = false)
00596 { return false; }
00597
00603 virtual bool setMultipleRows(const NamedList& data, const String& prefix = String::empty())
00604 { return false; }
00605
00616 virtual bool updateTableRows(const NamedList* data, bool atStart = false)
00617 { return false; }
00618
00626 virtual bool insertTableRow(const String& item, const String& before,
00627 const NamedList* data = 0)
00628 { return false; }
00629
00635 virtual bool delTableRow(const String& item)
00636 { return false; }
00637
00644 virtual bool setTableRow(const String& item, const NamedList* data)
00645 { return false; }
00646
00653 virtual bool getTableRow(const String& item, NamedList* data = 0)
00654 { return false; }
00655
00660 virtual bool clearTable()
00661 { return false; }
00662
00668 virtual bool setSelect(const String& item)
00669 { return false; }
00670
00676 virtual bool getSelect(String& item)
00677 { return false; }
00678
00686 virtual bool addLines(const NamedList& lines, unsigned int max, bool atStart = false)
00687 { return false; }
00688
00695 virtual bool setText(const String& text, bool richText = false)
00696 { return false; }
00697
00704 virtual bool getText(String& text, bool richText = false)
00705 { return false; }
00706 };
00707
00713 class YATE_API UIFactory : public String
00714 {
00715 YNOCOPY(UIFactory);
00716 public:
00720 explicit UIFactory(const char* name);
00721
00725 virtual ~UIFactory();
00726
00732 inline bool canBuild(const String& type)
00733 { return 0 != m_types.find(type); }
00734
00742 virtual void* create(const String& type, const char* name, NamedList* params = 0) = 0;
00743
00753 static void* build(const String& type, const char* name, NamedList* params = 0,
00754 const char* factory = 0);
00755
00756 protected:
00757 ObjList m_types;
00758
00759 private:
00760 static ObjList s_factories;
00761 };
00762
00767 class YATE_API Client : public Thread, public MessageReceiver
00768 {
00769 friend class Window;
00770 friend class ClientChannel;
00771 friend class ClientDriver;
00772 friend class ClientLogic;
00773 public:
00777 enum MsgID {
00778 CallCdr = 0,
00779 UiAction,
00780 UserLogin,
00781 UserNotify,
00782 ResourceNotify,
00783 ResourceSubscribe,
00784 ClientChanUpdate,
00785 UserRoster,
00786 ContactInfo,
00787
00788 ChanNotify,
00789 MucRoom,
00790
00791 MsgExecute,
00792 EngineStart,
00793 TransferNotify,
00794 UserData,
00795
00796 MsgIdCount
00797 };
00798
00802 enum ClientToggle {
00803 OptMultiLines = 0,
00804 OptAutoAnswer,
00805 OptRingIn,
00806 OptRingOut,
00807 OptActivateLastOutCall,
00808 OptActivateLastInCall,
00809 OptActivateCallOnSelect,
00810
00811 OptKeypadVisible,
00812 OptOpenIncomingUrl,
00813 OptAddAccountOnStartup,
00814 OptDockedChat,
00815 OptDestroyChat,
00816 OptNotifyChatState,
00817 OptCount
00818 };
00819
00823 enum TrayIconType {
00824 TrayIconMain = 0,
00825 TrayIconInfo = 1000,
00826 TrayIconIncomingChat = 3000,
00827 TrayIconNotification = 5000,
00828 TrayIconIncomingCall = 10000,
00829 };
00830
00835 explicit Client(const char *name = 0);
00836
00840 virtual ~Client();
00841
00845 virtual void run();
00846
00850 virtual void cleanup();
00851
00855 virtual void main() = 0;
00856
00860 virtual void lock() = 0;
00861
00865 virtual void unlock() = 0;
00866
00870 inline void lockOther()
00871 { if (!m_oneThread) lock(); }
00872
00876 inline void unlockOther()
00877 { if (!m_oneThread) unlock(); }
00878
00882 virtual void allHidden() = 0;
00883
00889 void loadUI(const char* file = 0, bool init = true);
00890
00894 virtual void quit() = 0;
00895
00901 bool openUrlSafe(const String& url);
00902
00908 virtual bool openUrl(const String& url) = 0;
00909
00916 virtual bool received(Message& msg, int id);
00917
00925 virtual bool createWindowSafe(const String& name,
00926 const String& alias = String::empty());
00927
00937 virtual bool createDialog(const String& name, Window* parent, const String& title,
00938 const String& alias = String::empty(), const NamedList* params = 0);
00939
00948 virtual bool createObject(void** dest, const String& type, const char* name,
00949 NamedList* params = 0);
00950
00957 virtual bool closeWindow(const String& name, bool hide = true);
00958
00966 virtual bool closeDialog(const String& name, Window* wnd, Window* skip = 0);
00967
00973 virtual bool debugHook(bool active);
00974
00980 virtual bool addToLog(const String& text);
00981
00988 virtual bool setStatus(const String& text, Window* wnd = 0);
00989
00996 bool setStatusLocked(const String& text, Window* wnd = 0);
00997
01005 bool setParams(const NamedList* params, Window* wnd = 0, Window* skip = 0);
01006
01015 virtual bool action(Window* wnd, const String& name, NamedList* params = 0);
01016
01025 virtual bool toggle(Window* wnd, const String& name, bool active);
01026
01036 virtual bool select(Window* wnd, const String& name, const String& item, const String& text = String::empty());
01037
01042 inline bool oneThread() const
01043 { return m_oneThread; }
01044
01049 inline int line() const
01050 { return m_line; }
01051
01056 void line(int newLine);
01057
01058 bool hasElement(const String& name, Window* wnd = 0, Window* skip = 0);
01059 bool setActive(const String& name, bool active, Window* wnd = 0, Window* skip = 0);
01060 bool setFocus(const String& name, bool select = false, Window* wnd = 0, Window* skip = 0);
01061 bool setShow(const String& name, bool visible, Window* wnd = 0, Window* skip = 0);
01062 bool setText(const String& name, const String& text, bool richText = false,
01063 Window* wnd = 0, Window* skip = 0);
01064 bool setCheck(const String& name, bool checked, Window* wnd = 0, Window* skip = 0);
01065 bool setSelect(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
01066 bool setUrgent(const String& name, bool urgent, Window* wnd = 0, Window* skip = 0);
01067 bool hasOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
01068
01077 virtual bool getOptions(const String& name, NamedList* items,
01078 Window* wnd = 0, Window* skip = 0);
01079
01080 bool addOption(const String& name, const String& item, bool atStart,
01081 const String& text = String::empty(), Window* wnd = 0, Window* skip = 0);
01082 bool delOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
01083
01094 bool addLines(const String& name, const NamedList* lines, unsigned int max,
01095 bool atStart = false, Window* wnd = 0, Window* skip = 0);
01096
01097 bool addTableRow(const String& name, const String& item, const NamedList* data = 0,
01098 bool atStart = false, Window* wnd = 0, Window* skip = 0);
01099
01108 bool setMultipleRows(const String& name, const NamedList& data, const String& prefix = String::empty(), Window* wnd = 0, Window* skip = 0);
01109
01120 bool insertTableRow(const String& name, const String& item,
01121 const String& before, const NamedList* data = 0,
01122 Window* wnd = 0, Window* skip = 0);
01123
01124 bool delTableRow(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
01125 bool setTableRow(const String& name, const String& item, const NamedList* data,
01126 Window* wnd = 0, Window* skip = 0);
01127 bool getTableRow(const String& name, const String& item, NamedList* data = 0,
01128 Window* wnd = 0, Window* skip = 0);
01129 bool clearTable(const String& name, Window* wnd = 0, Window* skip = 0);
01130
01141 bool updateTableRow(const String& name, const String& item, const NamedList* data = 0,
01142 bool atStart = false, Window* wnd = 0, Window* skip = 0);
01143
01157 bool updateTableRows(const String& name, const NamedList* data, bool atStart = false,
01158 Window* wnd = 0, Window* skip = 0);
01159
01169 bool getText(const String& name, String& text, bool richText = false, Window* wnd = 0, Window* skip = 0);
01170
01171 bool getCheck(const String& name, bool& checked, Window* wnd = 0, Window* skip = 0);
01172 bool getSelect(const String& name, String& item, Window* wnd = 0, Window* skip = 0);
01173
01198 bool buildMenu(const NamedList& params, Window* wnd = 0, Window* skip = 0);
01199
01210 bool removeMenu(const NamedList& params, Window* wnd = 0, Window* skip = 0);
01211
01220 virtual bool setImage(const String& name, const String& image,
01221 Window* wnd = 0, Window* skip = 0);
01222
01232 virtual bool setProperty(const String& name, const String& item, const String& value,
01233 Window* wnd = 0, Window* skip = 0);
01234
01244 virtual bool getProperty(const String& name, const String& item, String& value,
01245 Window* wnd = 0, Window* skip = 0);
01246
01247 void moveRelated(const Window* wnd, int dx, int dy);
01248 inline bool initialized() const
01249 { return m_initialized; }
01250 inline static Client* self()
01251 { return s_client; }
01252
01257 static inline bool valid()
01258 { return self() && (self() == Thread::current() || !(exiting() || Engine::exiting())); }
01259
01265 static bool isClientMsg(Message& msg);
01266
01267 inline static bool changing()
01268 { return (s_changing > 0); }
01269 static Window* getWindow(const String& name);
01270 static bool setVisible(const String& name, bool show = true, bool activate = false);
01271 static bool getVisible(const String& name);
01272 static bool openPopup(const String& name, const NamedList* params = 0, const Window* parent = 0);
01273 static bool openMessage(const char* text, const Window* parent = 0, const char* context = 0);
01274 static bool openConfirm(const char* text, const Window* parent = 0, const char* context = 0);
01275 static ObjList* listWindows();
01276 void idleActions();
01277
01285 bool postpone(const Message& msg, int id, bool copyUserData = false);
01286
01295 virtual bool chooseFile(Window* parent, NamedList& params)
01296 { return false; }
01297
01308 virtual bool setClientParam(const String& param, const String& value,
01309 bool save, bool update);
01310
01317 virtual bool backspace(const String& name, Window* wnd = 0);
01318
01326 void installRelay(const char* name, int id, int prio);
01327
01332 virtual bool callRouting(Message& msg)
01333 { return true;}
01334
01339 virtual bool imRouting(Message& msg)
01340 { return true;}
01341
01346 virtual bool imExecute(Message& msg);
01347
01358 virtual bool buildIncomingChannel(Message& msg, const String& dest);
01359
01365 virtual bool buildOutgoingChannel(NamedList& params);
01366
01374 bool callIncoming(Message& msg, const String& dest);
01375
01382 void callAnswer(const String& id, bool setActive = true);
01383
01391 void callTerminate(const String& id, const char* reason = 0, const char* error = 0);
01392
01397 ClientChannel* getActiveChannel();
01398
01406 virtual bool ringer(bool in, bool on);
01407
01415 virtual bool createSound(const char* name, const char* file, const char* device = 0)
01416 { return false; }
01417
01424 bool emitDigits(const char* digits, const String& id = String::empty());
01425
01432 inline bool emitDigit(char digit, const String& id = String::empty()) {
01433 char s[2] = {digit,0};
01434 return emitDigits(s,id);
01435 }
01436
01442 inline bool getBoolOpt(ClientToggle toggle)
01443 { return toggle < OptCount ? m_toggles[toggle] : false; }
01444
01452 bool setBoolOpt(ClientToggle toggle, bool value, bool updateUi = false);
01453
01462 virtual bool formatDateTime(String& dest, unsigned int secs, const char* format,
01463 bool utc = false)
01464 { return false; }
01465
01470 static inline bool exiting()
01471 { return s_exiting; }
01472
01478 static bool getActive(const String& name);
01479
01488 static Message* buildMessage(const char* msg, const String& account,
01489 const char* oper = 0);
01490
01498 static Message* buildNotify(bool online, const String& account,
01499 const ClientResource* from = 0);
01500
01511 static Message* buildSubscribe(bool request, bool ok, const String& account,
01512 const String& contact, const char* proto = 0);
01513
01522 static Message* buildUserRoster(bool update, const String& account,
01523 const String& contact, const char* proto = 0);
01524
01530 static bool addLogic(ClientLogic* logic);
01531
01536 static void removeLogic(ClientLogic* logic);
01537
01543 static ClientLogic* findLogic(const String& name);
01544
01553 static Message* eventMessage(const String& event, Window* wnd = 0,
01554 const char* name = 0, NamedList* params = 0);
01555
01563 static bool save(Configuration& cfg, Window* parent = 0, bool showErr = true);
01564
01570 static ClientToggle getBoolOpt(const String& name);
01571
01575 static inline void setLogicsTick()
01576 { s_idleLogicsTick = true; }
01577
01585 static void appendEscape(String& buf, ObjList& list, char sep = ',', bool force = false);
01586
01594 static ObjList* splitUnescape(const String& buf, char sep = ',', bool emptyOk = false);
01595
01601 static void removeChars(String& buf, const char* chars);
01602
01611 static void fixPhoneNumber(String& number, const char* chars = 0);
01612
01622 static bool addTrayIcon(const String& wndName, int prio, NamedList* params);
01623
01632 static bool removeTrayIcon(const String& wndName, const String& name);
01633
01641 static bool updateTrayIcon(const String& wndName);
01642
01648 static void generateGuid(String& buf, const String& extra = String::empty());
01649
01655 static void plain2html(String& buf, bool spaceEol = false);
01656
01657 static Configuration s_settings;
01658 static Configuration s_actions;
01659 static Configuration s_accounts;
01660 static Configuration s_contacts;
01661 static Configuration s_providers;
01662 static Configuration s_history;
01663 static Configuration s_calltoHistory;
01664
01665 static Regexp s_notSelected;
01666
01667
01668 static Regexp s_guidRegexp;
01669
01670 static String s_skinPath;
01671 static String s_soundPath;
01672
01673 static String s_ringInName;
01674
01675 static String s_ringOutName;
01676
01677 static String s_statusWidget;
01678
01679 static String s_debugWidget;
01680
01681 static String s_toggles[OptCount];
01682
01683 static bool s_engineStarted;
01684
01685 protected:
01691 virtual ClientLogic* createDefaultLogic();
01692 virtual bool createWindow(const String& name,
01693 const String& alias = String::empty()) = 0;
01694 virtual void loadWindows(const char* file = 0) = 0;
01695 virtual void initWindows();
01696 virtual void initClient();
01697 virtual void exitClient()
01698 {}
01699 inline bool needProxy() const
01700 { return m_oneThread && !isCurrent(); }
01701 bool driverLockLoop();
01702 static bool driverLock(long maxwait = 0);
01703 static void driverUnlock();
01704
01705 static bool s_exiting;
01706
01707 ObjList m_windows;
01708 bool m_initialized;
01709 int m_line;
01710 bool m_oneThread;
01711 bool m_toggles[OptCount];
01712 ObjList m_relays;
01713 ClientLogic* m_defaultLogic;
01714 static Client* s_client;
01715 static int s_changing;
01716 static ObjList s_logics;
01717 static bool s_idleLogicsTick;
01718 };
01719
01724 class YATE_API ClientChannel : public Channel
01725 {
01726 friend class ClientDriver;
01727 YNOCOPY(ClientChannel);
01728 public:
01732 enum Notification {
01733 Startup,
01734 Destroyed,
01735 Active,
01736 OnHold,
01737 Mute,
01738 Noticed,
01739 AddrChanged,
01740 Routed,
01741 Accepted,
01742 Rejected,
01743 Progressing,
01744 Ringing,
01745 Answered,
01746 Transfer,
01747 Conference,
01748 AudioSet,
01749 Unknown
01750 };
01751
01757 ClientChannel(const Message& msg, const String& peerid);
01758
01764 ClientChannel(const String& target, const NamedList& params);
01765
01770 explicit ClientChannel(const String& soundId);
01771
01772 virtual ~ClientChannel();
01773
01780 bool start(const String& target, const NamedList& params);
01781
01782 virtual bool msgProgress(Message& msg);
01783 virtual bool msgRinging(Message& msg);
01784 virtual bool msgAnswered(Message& msg);
01785 virtual bool msgDrop(Message& msg, const char* reason);
01786 virtual bool callRouted(Message& msg);
01787 virtual void callAccept(Message& msg);
01788 virtual void callRejected(const char* error, const char* reason, const Message* msg);
01789
01794 void callAnswer(bool setActive = true);
01795
01800 inline const String& party() const
01801 { return m_party; }
01802
01807 inline bool conference() const
01808 { return m_conference; }
01809
01814 inline const String& transferId() const
01815 { return m_transferId; }
01816
01821 inline RefObject* clientData() const
01822 { return m_clientData; }
01823
01829 inline void setClientData(RefObject* obj = 0) {
01830 TelEngine::destruct(m_clientData);
01831 if (obj && obj->ref())
01832 m_clientData = obj;
01833 }
01834
01841 bool setMedia(bool open = false, bool replace = false);
01842
01849 bool setActive(bool active, bool update = true);
01850
01857 bool setMuted(bool on, bool update = true);
01858
01864 void setTransfer(const String& target = String::empty());
01865
01871 void setConference(const String& target = String::empty());
01872
01877 inline const String& peerOutFormat() const
01878 { return m_peerOutFormat; }
01879
01884 inline const String& peerInFormat() const
01885 { return m_peerInFormat; }
01886
01891 inline bool active() const
01892 { return m_active; }
01893
01898 inline bool muted() const
01899 { return m_muted; }
01900
01905 inline bool isNoticed() const
01906 { return m_noticed; }
01907
01911 void noticed();
01912
01917 inline int line() const
01918 { return m_line; }
01919
01924 void line(int newLine);
01925
01936 void update(int notif, bool chan = true,
01937 bool updatePeer = true, const char* engineMsg = 0,
01938 bool minimal = false, bool data = false);
01939
01946 static int lookup(const char* notif, int def = Unknown)
01947 { return TelEngine::lookup(notif,s_notification,def); }
01948
01955 static const char* lookup(int notif, const char* def = 0)
01956 { return TelEngine::lookup(notif,s_notification,def); }
01957
01961 static TokenDict s_notification[];
01962
01963 protected:
01964 virtual void destroyed();
01965 virtual void connected(const char* reason);
01966 virtual void disconnected(bool final, const char* reason);
01967
01968 inline bool peerHasSource(Message& msg) {
01969 CallEndpoint* ch = getPeer();
01970 if (!ch)
01971 ch = static_cast<CallEndpoint*>(msg.userObject("CallEndpoint"));
01972 return ch && ch->getSource();
01973 }
01974
01975
01976 void checkSilence();
01977
01978 String m_party;
01979 String m_peerOutFormat;
01980 String m_peerInFormat;
01981 String m_reason;
01982 String m_peerId;
01983 bool m_noticed;
01984 int m_line;
01985 bool m_active;
01986 bool m_silence;
01987 bool m_conference;
01988 bool m_muted;
01989 String m_transferId;
01990 RefObject* m_clientData;
01991 bool m_utility;
01992 String m_soundId;
01993 };
01994
01999 class YATE_API ClientDriver : public Driver
02000 {
02001 friend class ClientChannel;
02002 YNOCOPY(ClientDriver);
02003 public:
02004 ClientDriver();
02005 virtual ~ClientDriver();
02006 virtual void initialize() = 0;
02007 virtual bool msgExecute(Message& msg, String& dest);
02008 virtual void msgTimer(Message& msg);
02009 virtual bool msgRoute(Message& msg);
02010 virtual bool received(Message& msg, int id);
02011
02016 inline const String& activeId() const
02017 { return m_activeId; }
02018
02027 bool setActive(const String& id = String::empty());
02028
02034 ClientChannel* findLine(int line);
02035
02040 inline static ClientDriver* self()
02041 { return s_driver; }
02042
02047 inline static const String& device()
02048 { return s_device; }
02049
02054 static void dropCalls(const char* reason = 0);
02055
02062 static bool setAudioTransfer(const String& id, const String& target = String::empty());
02063
02072 static bool setConference(const String& id, bool in, const String* confName = 0);
02073
02079 static ClientChannel* findChan(const String& id);
02080
02086 static ClientChannel* findChanByPeer(const String& peer);
02087
02092 static ClientChannel* findActiveChan()
02093 { return self() ? findChan(self()->activeId()) : 0; }
02094
02098 static String s_confName;
02099
02104 static bool s_dropConfPeer;
02105
02106 protected:
02107 void setup();
02108 static ClientDriver* s_driver;
02109 static String s_device;
02110 String m_activeId;
02111 };
02112
02119 class YATE_API ClientLogic : public GenObject
02120 {
02121 friend class Client;
02122 YNOCOPY(ClientLogic);
02123 public:
02127 virtual ~ClientLogic();
02128
02133 inline const String& name() const
02134 { return m_name; }
02135
02140 inline int priority() const
02141 { return m_prio; }
02142
02147 virtual const String& toString() const;
02148
02154 bool setParams(const NamedList& params);
02155
02163 virtual bool action(Window* wnd, const String& name, NamedList* params = 0)
02164 { return false; }
02165
02173 virtual bool toggle(Window* wnd, const String& name, bool active)
02174 { return false; }
02175
02184 virtual bool select(Window* wnd, const String& name, const String& item,
02185 const String& text = String::empty())
02186 { return false; }
02187
02196 virtual bool setClientParam(const String& param, const String& value,
02197 bool save, bool update)
02198 { return false; }
02199
02204 virtual bool imIncoming(Message& msg)
02205 { return false; }
02206
02214 virtual bool callIncoming(Message& msg, const String& dest)
02215 { return false; }
02216
02225 virtual bool callStart(NamedList& params, Window* wnd = 0,
02226 const String& cmd = String::empty())
02227 { return false; }
02228
02235 virtual bool line(const String& name, Window* wnd = 0);
02236
02244 virtual bool display(NamedList& params, bool widget, Window* wnd = 0);
02245
02252 virtual bool backspace(const String& name, Window* wnd = 0);
02253
02260 virtual bool command(const String& name, Window* wnd = 0);
02261
02272 virtual bool debug(const String& name, bool active, Window* wnd = 0);
02273
02281 virtual bool editAccount(bool newAcc, NamedList* params, Window* wnd = 0)
02282 { return false; }
02283
02290 virtual bool acceptAccount(NamedList* params, Window* wnd = 0)
02291 { return false; }
02292
02299 virtual bool delAccount(const String& account, Window* wnd = 0)
02300 { return false; }
02301
02309 virtual bool updateAccount(const NamedList& account, bool login, bool save)
02310 { return false; }
02311
02318 virtual bool loginAccount(const NamedList& account, bool login)
02319 { return false; }
02320
02329 virtual bool updateContact(const NamedList& contact, bool save, bool update)
02330 { return false; }
02331
02338 virtual bool acceptContact(NamedList* params, Window* wnd = 0)
02339 { return false; }
02340
02348 virtual bool editContact(bool newCont, NamedList* params = 0, Window* wnd = 0)
02349 { return false; }
02350
02357 virtual bool delContact(const String& contact, Window* wnd = 0)
02358 { return false; }
02359
02366 virtual bool callContact(NamedList* params = 0, Window* wnd = 0)
02367 { return false; }
02368
02376 virtual bool updateProviders(const NamedList& provider, bool save, bool update)
02377 { return false; }
02378
02386 virtual bool callLogUpdate(const NamedList& params, bool save, bool update)
02387 { return false; }
02388
02394 virtual bool callLogDelete(const String& billid)
02395 { return false; }
02396
02405 virtual bool callLogClear(const String& table, const String& direction)
02406 { return false; }
02407
02414 virtual bool callLogCall(const String& billid, Window* wnd = 0)
02415 { return false; }
02416
02422 virtual bool callLogCreateContact(const String& billid)
02423 { return false; }
02424
02431 virtual bool help(const String& action, Window* wnd)
02432 { return false; }
02433
02438 virtual bool calltoLoaded()
02439 { return false; }
02440
02444 virtual void loadedWindows()
02445 {}
02446
02450 virtual void initializedWindows()
02451 {}
02452
02459 virtual bool initializedClient()
02460 { return false; }
02461
02466 virtual void exitingClient()
02467 {}
02468
02475 virtual bool handleUiAction(Message& msg, bool& stopLogic)
02476 { return false; }
02477
02484 virtual bool handleCallCdr(Message& msg, bool& stopLogic)
02485 { return false; }
02486
02493 virtual bool handleUserLogin(Message& msg, bool& stopLogic)
02494 { return false; }
02495
02502 virtual bool handleUserNotify(Message& msg, bool& stopLogic)
02503 { return false; }
02504
02511 virtual bool handleUserRoster(Message& msg, bool& stopLogic)
02512 { return false; }
02513
02520 virtual bool handleResourceNotify(Message& msg, bool& stopLogic)
02521 { return false; }
02522
02529 virtual bool handleResourceSubscribe(Message& msg, bool& stopLogic)
02530 { return false; }
02531
02538 virtual bool handleClientChanUpdate(Message& msg, bool& stopLogic)
02539 { return false; }
02540
02547 virtual bool handleContactInfo(Message& msg, bool& stopLogic)
02548 { return false; }
02549
02559 virtual bool defaultMsgHandler(Message& msg, int id, bool& stopLogic)
02560 { return false; }
02561
02566 virtual void engineStart(Message& msg)
02567 {}
02568
02575 virtual bool addDurationUpdate(DurationUpdate* duration, bool autoDelete = false);
02576
02583 virtual bool removeDurationUpdate(const String& name, bool delObj = false);
02584
02591 virtual bool removeDurationUpdate(DurationUpdate* duration, bool delObj = false);
02592
02599 virtual DurationUpdate* findDurationUpdate(const String& name, bool ref = true);
02600
02604 virtual void clearDurationUpdate();
02605
02609 virtual void destruct();
02610
02617 static const String& cdrRemoteParty(const NamedList& params, bool outgoing)
02618 { return outgoing ? params["called"] : params["caller"]; }
02619
02625 static const String& cdrRemoteParty(const NamedList& params) {
02626 const String& dir = params["direction"];
02627 if (dir == "incoming")
02628 return cdrRemoteParty(params,true);
02629 if (dir == "outgoing")
02630 return cdrRemoteParty(params,false);
02631 return String::empty();
02632 }
02633
02638 static void initStaticData();
02639
02647 static bool saveContact(Configuration& cfg, ClientContact* c, bool save = true);
02648
02656 static bool clearContact(Configuration& cfg, ClientContact* c, bool save = true);
02657
02658
02659 static ObjList s_accOptions;
02660
02661 static const char* s_provParams[];
02662
02663 static ObjList s_protocols;
02664
02665 static Mutex s_protocolsMutex;
02666
02667 protected:
02673 ClientLogic(const char* name, int priority);
02674
02680 virtual void idleTimerTick(Time& time)
02681 {}
02682
02683 ObjList m_durationUpdate;
02684 Mutex m_durationMutex;
02685
02686 private:
02687 ClientLogic() {}
02688
02689 String m_name;
02690 int m_prio;
02691 };
02692
02693
02698 class YATE_API DefaultLogic : public ClientLogic
02699 {
02700 YNOCOPY(DefaultLogic);
02701 public:
02707 explicit DefaultLogic(const char* name = "default", int prio = -100);
02708
02712 ~DefaultLogic();
02713
02721 virtual bool action(Window* wnd, const String& name, NamedList* params = 0);
02722
02730 virtual bool toggle(Window* wnd, const String& name, bool active);
02731
02740 virtual bool select(Window* wnd, const String& name, const String& item,
02741 const String& text = String::empty());
02742
02751 virtual bool setClientParam(const String& param, const String& value,
02752 bool save, bool update);
02753
02758 virtual bool imIncoming(Message& msg);
02759
02767 virtual bool callIncoming(Message& msg, const String& dest);
02768
02777 virtual bool callStart(NamedList& params, Window* wnd = 0,
02778 const String& cmd = String::empty());
02779
02787 virtual bool digitPressed(NamedList& params, Window* wnd = 0);
02788
02796 virtual bool editAccount(bool newAcc, NamedList* params, Window* wnd = 0);
02797
02804 virtual bool acceptAccount(NamedList* params, Window* wnd = 0);
02805
02812 virtual bool delAccount(const String& account, Window* wnd = 0);
02813
02821 virtual bool updateAccount(const NamedList& account, bool login, bool save);
02822
02829 virtual bool loginAccount(const NamedList& account, bool login);
02830
02839 virtual bool updateContact(const NamedList& contact, bool save, bool update);
02840
02847 virtual bool acceptContact(NamedList* params, Window* wnd = 0);
02848
02856 virtual bool editContact(bool newCont, NamedList* params = 0, Window* wnd = 0);
02857
02864 virtual bool delContact(const String& contact, Window* wnd = 0);
02865
02872 virtual bool callContact(NamedList* params = 0, Window* wnd = 0);
02873
02881 virtual bool updateProviders(const NamedList& provider, bool save, bool update);
02882
02890 virtual bool callLogUpdate(const NamedList& params, bool save, bool update);
02891
02897 virtual bool callLogDelete(const String& billid);
02898
02907 virtual bool callLogClear(const String& table, const String& direction);
02908
02915 virtual bool callLogCall(const String& billid, Window* wnd = 0);
02916
02922 virtual bool callLogCreateContact(const String& billid);
02923
02930 virtual bool help(const String& action, Window* wnd);
02931
02936 virtual bool calltoLoaded();
02937
02941 virtual void loadedWindows()
02942 {}
02943
02947 virtual void initializedWindows();
02948
02955 virtual bool initializedClient();
02956
02961 virtual void exitingClient();
02962
02969 virtual bool handleUiAction(Message& msg, bool& stopLogic);
02970
02977 virtual bool handleCallCdr(Message& msg, bool& stopLogic);
02978
02985 virtual bool handleUserLogin(Message& msg, bool& stopLogic);
02986
02993 virtual bool handleUserNotify(Message& msg, bool& stopLogic);
02994
03001 virtual bool handleUserRoster(Message& msg, bool& stopLogic);
03002
03009 virtual bool handleResourceNotify(Message& msg, bool& stopLogic);
03010
03017 virtual bool handleResourceSubscribe(Message& msg, bool& stopLogic);
03018
03025 virtual bool handleClientChanUpdate(Message& msg, bool& stopLogic);
03026
03033 virtual bool handleContactInfo(Message& msg, bool& stopLogic);
03034
03044 virtual bool defaultMsgHandler(Message& msg, int id, bool& stopLogic);
03045
03051 virtual void updateSelectedChannel(const String* item = 0);
03052
03057 virtual void engineStart(Message& msg);
03058
03059 protected:
03065 virtual void idleTimerTick(Time& time);
03066
03072 virtual bool enableCallActions(const String& id);
03073
03080 virtual bool fillCallStart(NamedList& p, Window* wnd = 0);
03081
03087 virtual void channelSelectionChanged(const String& old);
03088
03095 virtual void fillContactEditActive(NamedList& list, bool active, const String* item = 0);
03096
03103 virtual void fillLogContactActive(NamedList& list, bool active, const String* item = 0);
03104
03112 virtual bool clearList(const String& action, Window* wnd);
03113
03122 virtual bool deleteItem(const String& list, const String& item, Window* wnd,
03123 bool confirm);
03124
03133 virtual bool deleteSelectedItem(const String& action, Window* wnd);
03134
03141 virtual bool handleTextChanged(NamedList* params, Window* wnd);
03142
03150 virtual bool handleFileTransferAction(const String& name, Window* wnd, NamedList* params = 0);
03151
03159 virtual bool handleFileTransferNotify(Message& msg, bool& stopLogic);
03160
03167 virtual bool handleUserData(Message& msg, bool& stopLogic);
03168
03176 virtual void notifyGenericError(const String& text,
03177 const String& account = String::empty(),
03178 const String& contact = String::empty(),
03179 const char* title = "Error");
03180
03188 virtual void notifyNoAudio(bool show, bool micOk = false, bool speakerOk = false,
03189 ClientChannel* chan = 0);
03190
03197 virtual void updateChatRoomsContactList(bool load, ClientAccount* acc,
03198 MucRoom* room = 0);
03199
03205 virtual void joinRoom(MucRoom* room, bool force = false);
03206
03207 String m_selectedChannel;
03208 String m_transferInitiated;
03209
03210 private:
03211
03212
03213 bool updateAccount(const NamedList& account, bool save,
03214 const String& replace = String::empty(), bool loaded = false);
03215
03216 bool internalEditAccount(bool newAcc, const String* account, NamedList* params, Window* wnd);
03217
03218 bool handleDialogAction(const String& name, bool& retVal, Window* wnd);
03219
03220 bool handleChatContactAction(const String& name, Window* wnd);
03221
03222 bool handleChatContactEditOk(const String& name, Window* wnd);
03223
03224 bool handleChatRoomEditOk(const String& name, Window* wnd);
03225
03226 bool handleMucsAction(const String& name, Window* wnd, NamedList* params);
03227
03228 bool handleMucInviteOk(Window* wnd);
03229
03230 bool handleMucsSelect(const String& name, const String& item, Window* wnd,
03231 const String& text = String::empty());
03232
03233
03234 bool handleMucResNotify(Message& msg, ClientAccount* acc, const String& contact,
03235 const String& instance, const String& operation);
03236
03237
03238 bool showNotificationArea(bool show, Window* wnd, NamedList* upd = 0,
03239 const char* notif = "notification");
03240
03241 void showUserRosterNotification(ClientAccount* a, const String& oper,
03242 Message& msg, const String& contactUri = String::empty(),
03243 bool newContact = true);
03244
03245 bool handleNotificationAreaAction(const String& action, Window* wnd);
03246
03247 bool storeContact(ClientContact* c);
03248
03249 ClientAccountList* m_accounts;
03250 };
03251
03252
03257 class YATE_API ClientAccount : public RefObject, public Mutex
03258 {
03259 friend class ClientContact;
03260 friend class MucRoom;
03261 YNOCOPY(ClientAccount);
03262 public:
03271 explicit ClientAccount(const char* proto, const char* user, const char* host,
03272 bool startup, ClientContact* contact = 0);
03273
03280 explicit ClientAccount(const NamedList& params, ClientContact* contact = 0);
03281
03286 inline const NamedList& params() const
03287 { return m_params; }
03288
03293 inline ObjList& contacts()
03294 { return m_contacts; }
03295
03300 inline ObjList& mucs()
03301 { return m_mucs; }
03302
03307 inline ClientContact* contact() const
03308 { return m_contact; }
03309
03314 void setContact(ClientContact* contact);
03315
03320 inline const String& protocol() const
03321 { return m_params["protocol"]; }
03322
03327 inline bool hasChat() const
03328 { return protocol() == "jabber"; }
03329
03334 inline bool hasPresence() const
03335 { return protocol() == "jabber"; }
03336
03341 inline bool startup() const
03342 { return m_params.getBoolValue("enabled",true); }
03343
03348 inline void startup(bool ok)
03349 { m_params.setParam("enabled",String::boolText(ok)); }
03350
03355 virtual const String& toString() const
03356 { return m_params; }
03357
03362 ClientResource* resource(bool ref);
03363
03368 inline ClientResource& resource() const
03369 { return *m_resource; }
03370
03375 void setResource(ClientResource* res);
03376
03384 bool save(bool ok = true, bool savePwd = true);
03385
03392 virtual ClientContact* findContact(const String& id, bool ref = false);
03393
03402 virtual ClientContact* findContact(const String* name = 0, const String* uri = 0,
03403 const String* skipId = 0, bool ref = false);
03404
03412 virtual ClientContact* findContact(const String& id, const String& resid,
03413 bool ref = false);
03414
03421 virtual ClientContact* findContactByUri(const String& uri, bool ref = false);
03422
03429 virtual MucRoom* findRoom(const String& id, bool ref = false);
03430
03437 virtual MucRoom* findRoomByUri(const String& uri, bool ref = false);
03438
03445 virtual ClientContact* findAnyContact(const String& id, bool ref = false);
03446
03454 virtual ClientContact* appendContact(const String& id, const char* name,
03455 const char* uri = 0);
03456
03462 virtual ClientContact* appendContact(const NamedList& params);
03463
03470 virtual ClientContact* removeContact(const String& id, bool delObj = true);
03471
03477 virtual void clearRooms(bool saved, bool temp);
03478
03485 virtual Message* userlogin(bool login, const char* msg = "user.login");
03486
03495 virtual Message* userData(bool update, const String& data,
03496 const char* msg = "user.data");
03497
03502 virtual void fillItemParams(NamedList& list);
03503
03508 inline const String& dataDir() const
03509 { return m_params["datadirectory"]; }
03510
03518 virtual bool setupDataDir(String* errStr = 0, bool saveAcc = true);
03519
03527 virtual bool loadDataDirCfg(Configuration* cfg = 0,
03528 const char* file = "account.conf");
03529
03535 virtual void loadContacts(Configuration* cfg = 0);
03536
03542 virtual bool clearDataDir(String* errStr = 0);
03543
03544 NamedList m_params;
03545 Configuration m_cfg;
03546
03547 protected:
03548
03549 virtual void destroyed();
03550
03551 virtual void appendContact(ClientContact* contact, bool muc = false);
03552
03553 ObjList m_contacts;
03554 ObjList m_mucs;
03555
03556 private:
03557 ClientResource* m_resource;
03558 ClientContact* m_contact;
03559 };
03560
03565 class YATE_API ClientAccountList : public String, public Mutex
03566 {
03567 YNOCOPY(ClientAccountList);
03568 public:
03574 inline explicit ClientAccountList(const char* name, ClientAccount* localContacts = 0)
03575 : String(name), Mutex(true,"ClientAccountList"),
03576 m_localContacts(localContacts)
03577 { }
03578
03582 ~ClientAccountList();
03583
03588 inline ObjList& accounts()
03589 { return m_accounts; }
03590
03595 inline ClientAccount* localContacts() const
03596 { return m_localContacts; }
03597
03603 bool isLocalContact(ClientContact* c) const;
03604
03610 inline bool isLocalContact(const String& id) const
03611 { return m_localContacts && m_localContacts->findContact(id); }
03612
03619 virtual ClientAccount* findAccount(const String& id, bool ref = false);
03620
03628 virtual ClientContact* findContactByUri(const String& account, const String& uri,
03629 bool ref = false);
03630
03638 virtual ClientContact* findContact(const String& account, const String& id, bool ref = false);
03639
03646 virtual ClientContact* findContact(const String& builtId, bool ref = false);
03647
03655 virtual ClientContact* findContactByInstance(const String& id, String* instance = 0,
03656 bool ref = false);
03657
03664 virtual MucRoom* findRoom(const String& id, bool ref = false);
03665
03672 virtual MucRoom* findRoomByMember(const String& id, bool ref = false);
03673
03680 virtual ClientContact* findAnyContact(const String& id, bool ref = false);
03681
03688 virtual ClientAccount* findSingleRegAccount(const String* skipProto = 0,
03689 bool ref = false);
03690
03696 virtual bool appendAccount(ClientAccount* account);
03697
03702 virtual void removeAccount(const String& id);
03703
03704 protected:
03705 ObjList m_accounts;
03706
03707 private:
03708 ClientAccountList() {}
03709 ClientAccount* m_localContacts;
03710 };
03711
03717 class YATE_API ClientContact : public RefObject
03718 {
03719 friend class ClientAccount;
03720 YNOCOPY(ClientContact);
03721 public:
03729 explicit ClientContact(ClientAccount* owner, const char* id, const char* name = 0,
03730 const char* uri = 0);
03731
03740 explicit ClientContact(ClientAccount* owner, const NamedList& params, const char* id = 0,
03741 const char* uri = 0);
03742
03747 inline ClientAccount* account()
03748 { return m_owner; }
03749
03754 inline const String& accountName() const
03755 { return m_owner ? m_owner->toString() : String::empty(); }
03756
03761 inline const URI& uri() const
03762 { return m_uri; }
03763
03768 inline void setUri(const char* u)
03769 { m_uri = u; }
03770
03775 inline ObjList& resources()
03776 { return m_resources; }
03777
03782 inline bool online() const
03783 { return m_online || 0 != m_resources.skipNull(); }
03784
03789 inline void setOnline(bool on)
03790 { m_online = on; }
03791
03796 inline ObjList& groups()
03797 { return m_groups; }
03798
03804 inline bool local(bool defVal = false) const
03805 { return m_params.getBoolValue("local",defVal); }
03806
03811 inline void setLocal(bool on)
03812 { m_params.setParam("local",String::boolText(on)); }
03813
03819 inline bool remote(bool defVal = false) const
03820 { return m_params.getBoolValue("remote",defVal); }
03821
03826 inline void setRemote(bool on)
03827 { m_params.setParam("remote",String::boolText(on)); }
03828
03833 inline void setDockedChat(bool on) {
03834 if (!mucRoom())
03835 m_dockedChat = on;
03836 }
03837
03842 inline void getContactSection(String& buf) {
03843 String pref;
03844 buf = toString();
03845 buf.startSkip(buildContactId(pref,accountName(),String::empty()),false);
03846 buf = buf.uriUnescape();
03847 }
03848
03853 virtual const String& toString() const
03854 { return m_id; }
03855
03860 virtual MucRoom* mucRoom()
03861 { return 0; }
03862
03869 inline String& buildInstanceId(String& dest, const String& inst = String::empty()) {
03870 dest << m_id << "|" << inst.uriEscape('|');
03871 return dest;
03872 }
03873
03879 inline void buildIdHash(String& buf, const String& prefix = String::empty()) {
03880 MD5 md5(m_id);
03881 buf = prefix + md5.hexDigest();
03882 }
03883
03889 inline bool isChatWnd(Window* wnd)
03890 { return wnd && wnd->toString() == m_chatWndName; }
03891
03896 bool hasChat();
03897
03902 virtual void flashChat(bool on = true);
03903
03912 virtual bool sendChat(const char* body, const String& res = String::empty(),
03913 const String& type = String::empty(), const char* state = "active");
03914
03920 virtual void getChatInput(String& text, const String& name = "message");
03921
03927 virtual void setChatInput(const String& text = String::empty(),
03928 const String& name = "message");
03929
03936 virtual void getChatHistory(String& text, bool richText = false,
03937 const String& name = "history");
03938
03945 virtual void setChatHistory(const String& text, bool richText = false,
03946 const String& name = "history");
03947
03954 virtual void addChatHistory(const String& what, NamedList*& params,
03955 const String& name = "history");
03956
03963 virtual void getChatProperty(const String& name, const String& prop, String& value);
03964
03971 virtual void setChatProperty(const String& name, const String& prop, const String& value);
03972
03977 inline bool isChatVisible()
03978 { return Client::self() && Client::self()->getVisible(m_chatWndName); }
03979
03986 virtual bool showChat(bool visible, bool active = false);
03987
03992 Window* getChatWnd();
03993
03999 virtual void createChatWindow(bool force = false, const char* name = 0);
04000
04007 virtual void updateChatWindow(const NamedList& params, const char* title = 0,
04008 const char* icon = 0);
04009
04014 virtual bool isChatActive();
04015
04019 void destroyChatWindow();
04020
04026 virtual String* findGroup(const String& group);
04027
04033 virtual bool appendGroup(const String& group);
04034
04040 virtual bool removeGroup(const String& group);
04041
04048 virtual bool setGroups(const NamedList& list, const String& param);
04049
04055 virtual ClientResource* status(bool ref = false);
04056
04063 virtual ClientResource* findResource(const String& id, bool ref = false);
04064
04070 virtual ClientResource* findAudioResource(bool ref = false);
04071
04077 virtual ClientResource* findFileTransferResource(bool ref = false);
04078
04084 virtual ClientResource* appendResource(const String& id);
04085
04092 virtual bool insertResource(ClientResource* res);
04093
04099 virtual bool removeResource(const String& id);
04100
04108 static inline String& buildContactId(String& dest, const String& account,
04109 const String& contact) {
04110 dest << account.uriEscape('|') << "|" << String::uriEscape(contact,'|').toLower();
04111 return dest;
04112 }
04113
04119 static inline void splitContactId(const String& src, String& account) {
04120 int pos = src.find('|');
04121 if (pos >= 0)
04122 account = src.substr(0,pos).uriUnescape();
04123 else
04124 account = src.uriUnescape();
04125 }
04126
04134 static void splitContactInstanceId(const String& src, String& account,
04135 String& contact, String* instance = 0);
04136
04137
04138 static String s_chatPrefix;
04139
04140 static String s_dockedChatWnd;
04141
04142 static String s_dockedChatWidget;
04143
04144 static String s_mucsWnd;
04145
04146 static String s_chatInput;
04147
04148 String m_name;
04149 String m_subscription;
04150 NamedList m_params;
04151
04152 protected:
04159 explicit ClientContact(ClientAccount* owner, const char* id, bool mucRoom);
04160
04164 void removeFromOwner();
04165
04169 virtual void destroyed();
04170
04171 ClientAccount* m_owner;
04172 bool m_online;
04173 String m_id;
04174 URI m_uri;
04175 ObjList m_resources;
04176 ObjList m_groups;
04177 bool m_dockedChat;
04178 String m_chatWndName;
04179 };
04180
04185 class YATE_API ClientResource : public RefObject
04186 {
04187 YCLASS(ClientResource,RefObject)
04188 YNOCOPY(ClientResource);
04189 public:
04193 enum Status {
04194 Unknown = 0,
04195 Offline = 1,
04196 Connecting = 2,
04197 Online = 3,
04198 Busy = 4,
04199 Dnd = 5,
04200 Away = 6,
04201 Xa = 7,
04202 };
04203
04210 inline explicit ClientResource(const char* id, const char* name = 0, bool audio = true)
04211 : m_id(id), m_name(name ? name : id), m_audio(audio), m_fileTransfer(false),
04212 m_priority(0), m_status(Offline)
04213 { }
04214
04219 virtual const String& toString() const
04220 { return m_id; }
04221
04226 inline bool online() const
04227 { return m_status > Connecting; }
04228
04233 inline bool offline() const
04234 { return m_status == Offline; }
04235
04240 inline const char* statusName() const
04241 { return lookup(m_status,s_statusName); }
04242
04247 inline const char* text() const
04248 { return m_text ? m_text.c_str() : statusDisplayText(m_status); }
04249
04255 inline bool setAudio(bool ok) {
04256 if (m_audio == ok)
04257 return false;
04258 m_audio = ok;
04259 return true;
04260 }
04261
04267 inline bool setFileTransfer(bool ok) {
04268 if (m_fileTransfer == ok)
04269 return false;
04270 m_fileTransfer = ok;
04271 return true;
04272 }
04273
04279 inline bool setPriority(int prio) {
04280 if (m_priority == prio)
04281 return false;
04282 m_priority = prio;
04283 return true;
04284 }
04285
04291 inline bool setStatus(int stat) {
04292 if (m_status == stat)
04293 return false;
04294 m_status = stat;
04295 return true;
04296 }
04297
04303 inline bool setStatusText(const String& text = String::empty()) {
04304 if (m_text == text)
04305 return false;
04306 m_text = text;
04307 return true;
04308 }
04309
04316 static inline const char* statusDisplayText(int status, const char* defVal = 0)
04317 { return lookup(status,s_statusName,defVal); }
04318
04322 static const TokenDict s_statusName[];
04323
04324 String m_id;
04325 String m_name;
04326 bool m_audio;
04327 bool m_fileTransfer;
04328 int m_priority;
04329 int m_status;
04330 String m_text;
04331 };
04332
04338 class YATE_API MucRoomMember : public ClientResource
04339 {
04340 YCLASS(MucRoomMember,ClientResource)
04341 YNOCOPY(MucRoomMember);
04342 public:
04346 enum Affiliation {
04347 AffUnknown = 0,
04348 AffNone,
04349 Outcast,
04350 Member,
04351 Admin,
04352 Owner
04353 };
04354
04358 enum Role {
04359 RoleUnknown = 0,
04360 RoleNone,
04361 Visitor,
04362 Participant,
04363 Moderator
04364 };
04365
04372 inline explicit MucRoomMember(const char* id, const char* nick, const char* uri = 0)
04373 : ClientResource(id,nick),
04374 m_uri(uri), m_affiliation(AffNone), m_role(RoleNone)
04375 {}
04376
04380 static const TokenDict s_affName[];
04381
04385 static const TokenDict s_roleName[];
04386
04387 String m_uri;
04388 String m_instance;
04389 int m_affiliation;
04390 int m_role;
04391 };
04392
04402 class YATE_API MucRoom : public ClientContact
04403 {
04404 YCLASS(MucRoom,ClientContact)
04405 YNOCOPY(MucRoom);
04406 public:
04415 explicit MucRoom(ClientAccount* owner, const char* id, const char* name, const char* uri,
04416 const char* nick = 0);
04417
04422 inline MucRoomMember& resource()
04423 { return *m_resource; }
04424
04430 inline bool ownMember(MucRoomMember* item) const
04431 { return m_resource == item; }
04432
04438 inline bool ownMember(const String& item) const
04439 { return m_resource->toString() == item; }
04440
04445 inline bool available() const {
04446 return m_resource->online() &&
04447 m_resource->m_role > MucRoomMember::RoleNone;
04448 }
04449
04454 inline bool canChat() const
04455 { return available() && m_resource->m_role >= MucRoomMember::Visitor; }
04456
04461 inline bool canChatPrivate() const
04462 { return available(); }
04463
04468 inline bool canChangeSubject() const
04469 { return available() && m_resource->m_role == MucRoomMember::Moderator; }
04470
04475 inline bool canInvite() const
04476 { return available(); }
04477
04483 bool canKick(MucRoomMember* member) const;
04484
04490 bool canBan(MucRoomMember* member) const;
04491
04497 inline Message* buildMucRoom(const char* oper) {
04498 Message* m = Client::buildMessage("muc.room",accountName(),oper);
04499 m->addParam("room",uri());
04500 return m;
04501 }
04502
04510 Message* buildJoin(bool join, bool history = true, unsigned int sNewer = 0);
04511
04516 virtual MucRoom* mucRoom()
04517 { return this; }
04518
04524 virtual ClientResource* status(bool ref = false)
04525 { return (!ref || m_resource->ref()) ? m_resource : 0; }
04526
04532 MucRoomMember* findMember(const String& nick);
04533
04540 MucRoomMember* findMember(const String& contact, const String& instance);
04541
04547 MucRoomMember* findMemberById(const String& id);
04548
04554 bool hasChat(const String& id);
04555
04561 virtual void flashChat(const String& id, bool on = true);
04562
04569 virtual void getChatInput(const String& id, String& text, const String& name = "message");
04570
04577 virtual void setChatInput(const String& id, const String& text = String::empty(),
04578 const String& name = "message");
04579
04587 virtual void getChatHistory(const String& id, String& text, bool richText = false,
04588 const String& name = "history");
04589
04597 virtual void setChatHistory(const String& id, const String& text, bool richText = false,
04598 const String& name = "history");
04599
04607 virtual void addChatHistory(const String& id, const String& what, NamedList*& params,
04608 const String& name = "history");
04609
04617 virtual void setChatProperty(const String& id, const String& name, const String& prop,
04618 const String& value);
04619
04627 virtual bool showChat(const String& id, bool visible, bool active = false);
04628
04635 virtual void createChatWindow(const String& id, bool force = false, const char* name = 0);
04636
04642 virtual void updateChatWindow(const String& id, const NamedList& params);
04643
04648 virtual bool isChatActive(const String& id);
04649
04654 void destroyChatWindow(const String& id = String::empty());
04655
04662 virtual ClientResource* findResource(const String& id, bool ref = false);
04663
04669 virtual ClientResource* appendResource(const String& nick);
04670
04677 virtual bool insertResource(ClientResource* res)
04678 { return false; }
04679
04686 virtual bool removeResource(const String& nick, bool delChat = false);
04687
04691 String m_password;
04692
04693 protected:
04694
04695 virtual void destroyed();
04696
04697 private:
04698 unsigned int m_index;
04699 MucRoomMember* m_resource;
04700 };
04701
04707 class YATE_API DurationUpdate : public RefObject
04708 {
04709 YNOCOPY(DurationUpdate);
04710 public:
04719 inline DurationUpdate(ClientLogic* logic, bool owner, const char* id,
04720 const char* name, unsigned int start = Time::secNow())
04721 : m_id(id), m_logic(0), m_name(name), m_startTime(start)
04722 { setLogic(logic,owner); }
04723
04727 virtual ~DurationUpdate();
04728
04733 virtual const String& toString() const;
04734
04740 void setLogic(ClientLogic* logic = 0, bool owner = true);
04741
04751 virtual unsigned int update(unsigned int secNow, const String* table = 0,
04752 Window* wnd = 0, Window* skip = 0, bool force = false);
04753
04761 virtual unsigned int buildTimeParam(NamedList& dest, unsigned int secNow,
04762 bool force = false);
04763
04771 virtual unsigned int buildTimeString(String& dest, unsigned int secNow,
04772 bool force = false);
04773
04783 static unsigned int buildTimeParam(NamedList& dest, const char* param, unsigned int secStart,
04784 unsigned int secNow, bool force = false);
04785
04794 static unsigned int buildTimeString(String& dest, unsigned int secStart, unsigned int secNow,
04795 bool force = false);
04796
04797 protected:
04801 virtual void destroyed();
04802
04803 String m_id;
04804 ClientLogic* m_logic;
04805 String m_name;
04806 unsigned int m_startTime;
04807 };
04808
04813 class YATE_API ClientSound : public String
04814 {
04815 YNOCOPY(ClientSound);
04816 public:
04823 inline ClientSound(const char* name, const char* file, const char* device = 0)
04824 : String(name), m_native(false), m_file(file), m_device(device), m_repeat(0),
04825 m_started(false), m_stereo(false)
04826 { }
04827
04831 virtual ~ClientSound()
04832 { stop(); }
04833
04837 virtual void destruct() {
04838 stop();
04839 String::destruct();
04840 }
04841
04847 inline bool native() const
04848 { return m_native; }
04849
04854 inline bool started() const
04855 { return m_started; }
04856
04861 inline const String& device() const
04862 { return m_device; }
04863
04868 inline void device(const char* dev)
04869 { Lock lock(s_soundsMutex); m_device = dev; }
04870
04875 inline const String& file() const
04876 { return m_file; }
04877
04884 inline void file(const char* filename, bool stereo)
04885 { Lock lock(s_soundsMutex); m_file = filename; m_stereo = stereo; }
04886
04892 inline void setRepeat(unsigned int count)
04893 { m_repeat = count; }
04894
04899 inline bool stereo() const
04900 { return m_stereo; }
04901
04907 bool start(bool force = true);
04908
04912 void stop();
04913
04919 void setChannel(const String& chan, bool ok);
04920
04926 bool attachSource(ClientChannel* chan);
04927
04939 static bool build(const String& id, const char* file, const char* device = 0,
04940 unsigned int repeat = 0, bool resetExisting = true, bool stereo = false);
04941
04947 static bool started(const String& name);
04948
04955 static bool start(const String& name, bool force = true);
04956
04961 static void stop(const String& name);
04962
04969 static ClientSound* find(const String& token, bool byName = true);
04970
04974 static ObjList s_sounds;
04975
04979 static Mutex s_soundsMutex;
04980
04985 static String s_calltoPrefix;
04986
04987 protected:
04988 virtual bool doStart();
04989 virtual void doStop();
04990
04991 bool m_native;
04992 String m_file;
04993 String m_device;
04994 unsigned int m_repeat;
04995 bool m_started;
04996 bool m_stereo;
04997 String m_channel;
04998 };
04999
05000 };
05001
05002 #endif
05003
05004