internal ContactTabContent(ContactTabItem container, Contact contact)
        {
            InitializeComponent();

            tabItem = container;
            this.contact = contact;
        }
Esempio n. 2
0
 public ChatTabItem(MessagingWindow parentWindow, Contact contact)
 {
     window = parentWindow;
     Contact = contact;
     Header = Contact.Nickname;
     tabContent = new ChatTabContent();
     Content = tabContent;
 }
Esempio n. 3
0
 private void Plugin_MessageSentEvent(Contact contact,
     DateTime eventTime, string message)
 {
     ContactTabItem tab = GetContactTab(contact);
     if (tab != null)
     {
         tab.AddMessage(eventTime, message, false);
     }
 }
Esempio n. 4
0
        private ContactTabItem GetContactTab(Contact contact)
        {
            foreach (ContactTabItem item in MainTabControl.Items)
            {
                if (item.Contact == contact)
                {
                    return item;
                }
            }

            return null;
        }
Esempio n. 5
0
        private int CListDoubleClicked(IntPtr wParam, IntPtr lParam)
        {
            IntPtr hContact = wParam;
            var contact = new Contact(hContact);

            if (MessagingWindow == null)
            {
                MessagingWindow = new MessagingWindow(this);
                MessagingWindow.Visibility = Visibility.Visible;
            }

            if (ContactDoubleClickedEvent != null)
                ContactDoubleClickedEvent(contact);

            return 0;
        }
Esempio n. 6
0
        private void Plugin_ContactDoubleClickedEvent(Contact contact)
        {
            TabItem tab = GetContactTab(contact);
            if (tab != null)
                MainTabControl.SelectedItem = tab;
            else
            {
                var isChatRoom =
                    (byte)plugin.Database.GetContactSetting(contact,
                        contact.Protocol, "ChatRoom");

                if (isChatRoom != 0)
                    MainTabControl.Items.Add(new ContactTabItem(this,
                        contact));
                else
                    MainTabControl.Items.Add(new ChatTabItem(this, contact));
            }
        }
Esempio n. 7
0
 /// <summary>
 /// An event handler called when some contact status changed.
 /// </summary>
 private void contact_StatusChangedEvent(Contact sender, Contact.Status newStatus)
 {
     _storage.StoreStatus(sender, newStatus, DateTime.Now);
 }
Esempio n. 8
0
        private int EventAdded(IntPtr wParam, IntPtr lParam)
        {
            IntPtr hContact = wParam;
            IntPtr hDBEvent = lParam;

            int blobSize = this.CallService("DB/Event/GetBlobSize",
                hDBEvent, IntPtr.Zero).ToInt32();

            using (var pBlob = new AutoPtr(Marshal.AllocHGlobal(blobSize)))
            using (var pDBEventInfo = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                var eventInfo = new DBEventInfo();
                eventInfo.pBlob = pBlob;
                eventInfo.cbBlob = (uint)blobSize;

                Marshal.StructureToPtr(eventInfo, pDBEventInfo, false);
                this.CallService("DB/Event/Get", hDBEvent, pDBEventInfo);

                eventInfo = (DBEventInfo)Marshal.PtrToStructure(pDBEventInfo,
                    typeof (DBEventInfo));

                if (eventInfo.eventType == DBEventInfo.EVENTTYPE_MESSAGE)
                {
                    using (var pDBEventGetText = new AutoPtr(
                        Marshal.AllocHGlobal(Marshal.SizeOf(
                            typeof (DBEventGetText)))))
                    {
                        var getText = new DBEventGetText();
                        getText.dbei = pDBEventInfo;
                        getText.datatype = Utils.DBVT_ASCIIZ;
                        getText.codepage = 1251;

                        Marshal.StructureToPtr(getText, pDBEventGetText,
                            false);

                        IntPtr pString = this.CallService(
                            "DB/Event/GetText", IntPtr.Zero, pDBEventGetText);
                        string message = Marshal.PtrToStringAnsi(pString);

                        mmi.mmi_free(pString);

                        var contact = new Contact(hContact);

                        DateTime eventTime = new DateTime(1970, 1, 1).
                            AddSeconds(eventInfo.timestamp).ToUniversalTime();
                        if ((eventInfo.flags & DBEventInfo.DBEF_SENT) != 0)
                        {
                            if (MessageSentEvent != null)
                                MessageSentEvent(contact, eventTime, message);
                        }
                        else
                        {
                            if (MessageReceivedEvent != null)
                                MessageReceivedEvent(contact, eventTime,
                                    message);
                        }
                    }
                }
            }

            return 0;
        }
Esempio n. 9
0
 public bool Equals(Contact other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.hContact.Equals(hContact); // &&
     //Equals(other.pluginLink, pluginLink);
 }
Esempio n. 10
0
        /// <summary>
        /// Creates instance of history item and loads its content from
        /// database.
        /// </summary>
        /// <param name="contact">
        /// Contact with whom history this item is associated.
        /// </param>
        /// <param name="hEvent">
        /// Miranda event handle.
        /// </param>
        internal static HistoryItem Load(Contact contact,
            IntPtr hEvent)
        {
            if (hEvent == IntPtr.Zero)
                throw new ArgumentException("hEvent cannot be zero.");

            // Miranda interface for freeing strings:
            var mmi = MMInterface.GetMMI();

            using (var pDbEventInfo = new AutoPtr(Marshal.AllocHGlobal(
                Marshal.SizeOf(typeof (DBEventInfo)))))
            {
                var result = Plugin.m_CallService(
                    "DB/Event/Get",
                    hEvent,
                    pDbEventInfo);
                if (result != IntPtr.Zero)
                    throw new DatabaseException();

                var eventInfo =
                    (DBEventInfo)
                        Marshal.PtrToStructure(pDbEventInfo, typeof (DBEventInfo));

                var type = (HistoryItemType)eventInfo.eventType;
                var direction = (eventInfo.flags & DBEventInfo.DBEF_SENT) != 0
                    ? HistoryItemDirection.Outgoing
                    : HistoryItemDirection.Incoming;
                var historyItem = new HistoryItem(type, direction);
                if (type == HistoryItemType.Message)
                {
                    // Get message text:
                    using (var pDbEventGetText = new AutoPtr(
                        Marshal.AllocHGlobal(Marshal.SizeOf(
                            typeof (DBEventGetText)))))
                    {
                        var getText = new DBEventGetText();
                        getText.dbei = pDbEventInfo;
                        getText.datatype = Utils.DBVT_WCHAR;

                        Marshal.StructureToPtr(getText, pDbEventGetText, false);

                        var pString = Plugin.m_CallService(
                            "DB/Event/GetText",
                            IntPtr.Zero,
                            pDbEventGetText);
                        mmi.mmi_free(pString);

                        var message = Marshal.PtrToStringUni(pString);
                        historyItem.MessageText = message;
                    }
                }

                historyItem.Contact = contact;
                historyItem.DateTime = new DateTime(1970, 1, 1)
                    .AddSeconds(eventInfo.timestamp);

                return historyItem;
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Reads setting from database for specified contact. Setting can be:
 /// byte, short, int, string, byte[].
 /// </summary>
 /// <param name="contact">
 /// Reference to contact whose setting must be gotten.
 /// </param>
 /// <param name="moduleName">
 /// Name of module that wrote the setting to get.
 /// </param>
 /// <param name="settingName">
 /// Name of setting to get.
 /// </param>
 /// <returns>
 /// Object that may be casted to one of variant types.
 /// </returns>
 public object GetContactSetting(Contact contact, string moduleName,
     string settingName)
 {
     return GetSetting(contact.hContact, moduleName, settingName);
 }
Esempio n. 12
0
 /// <summary>
 /// Reads all setting names from database for spedified contact of
 /// specified module.
 /// </summary>
 /// <param name="contact">
 /// Contact whose settings must be gotten.
 /// </param>
 /// <param name="moduleName">
 /// Name of module that wrote the settings to get.
 /// </param>
 /// <returns>
 /// Array with setting names.
 /// </returns>
 public string[] EnumContactSettings(Contact contact, string moduleName)
 {
     return EnumContactSettings(contact.hContact, moduleName);
 }
Esempio n. 13
0
 /// <summary>
 /// Writes setting to database.
 /// </summary>
 /// <param name="Contact">
 /// Contact whose setting must be gotten.
 /// </param>
 /// <param name="moduleName">
 /// Name of module that wrote the setting to get.
 /// </param>
 /// <param name="settingName">
 /// Name of setting to get.
 /// <param name="value">
 /// Value of one of specified types: byte, ushort, short, uint, int,
 /// string, byte[].
 /// </param>
 public void SetContactSetting(Contact contact, string moduleName,
     string settingName, object value)
 {
     SetSetting(contact.hContact, moduleName, settingName, value);
 }