예제 #1
0
파일: CursesUI.cs 프로젝트: shubhtr/smuxi
        public void UpdateTopicInGroupChat(GroupChatModel cpage, MessageModel topic)
        {
            Trace.Call(cpage, topic);

            //Console.WriteLine("Topic changed to: "+topic+ " on "+cpage.Name);
        }
예제 #2
0
파일: CursesUI.cs 프로젝트: shubhtr/smuxi
 public void AddPersonToGroupChat(GroupChatModel cpage, PersonModel user)
 {
     Trace.Call(cpage, user);
 }
예제 #3
0
파일: CursesUI.cs 프로젝트: shubhtr/smuxi
 public void UpdatePersonInGroupChat(GroupChatModel cpage, PersonModel olduser, PersonModel newuser)
 {
     Trace.Call(cpage, olduser, newuser);
 }
예제 #4
0
 public XmppGroupChatView(GroupChatModel chat) : base(chat)
 {
     Trace.Call(chat);
 }
예제 #5
0
        public GroupChatView(GroupChatModel groupChat) : base(groupChat)
        {
            Trace.Call(groupChat);

            _GroupChatModel = groupChat;

            // person list
            Participants  = new List <PersonModel>();
            _OutputHPaned = new Gtk.HPaned();
            _OutputHPaned.ButtonPressEvent += (sender, e) => {;
                                                              // reset person list size on double click
                                                              if (e.Event.Type == Gdk.EventType.TwoButtonPress &&
                                                                  e.Event.Button == 1)
                                                              {
                                                                  GLib.Timeout.Add(200, delegate {
                        _OutputHPaned.Position = -1;
                        return(false);
                    });
                                                              }
            };

            Gtk.TreeView tv = new Gtk.TreeView();
            _PersonTreeView = tv;
            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            PersonScrolledWindow = sw;
            sw.HscrollbarPolicy  = Gtk.PolicyType.Never;
            sw.SizeRequested    += (o, args) => {
                // predict and set useful treeview width
                var persons = SyncedPersons;
                if (persons == null || persons.Count == 0)
                {
                    return;
                }

                int longestNameWidth = 0;
                foreach (var person in persons.Values)
                {
                    int lineWidth, lineHeigth;
                    using (var layout = _PersonTreeView.CreatePangoLayout(person.IdentityName)) {
                        layout.GetPixelSize(out lineWidth, out lineHeigth);
                    }
                    if (lineWidth > longestNameWidth)
                    {
                        longestNameWidth = lineWidth;
                    }
                }

                var bestSize = new Gtk.Requisition()
                {
                    Width = longestNameWidth
                };
                args.Requisition = bestSize;
            };

            //tv.CanFocus = false;
            tv.BorderWidth    = 0;
            tv.Selection.Mode = Gtk.SelectionMode.Multiple;
            sw.Add(tv);

            Gtk.TreeViewColumn   column;
            Gtk.CellRendererText cellr = new Gtk.CellRendererText();
            IdentityNameCellRenderer = cellr;
            column = new Gtk.TreeViewColumn(String.Empty, cellr);
            column.SortColumnId  = 0;
            column.Spacing       = 0;
            column.SortIndicator = false;
            column.Sizing        = Gtk.TreeViewColumnSizing.Autosize;
            // FIXME: this callback leaks memory
            column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName));
            tv.AppendColumn(column);
            _IdentityNameColumn = column;

            Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel));
            liststore.SetSortColumnId(0, Gtk.SortType.Ascending);
            liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore));
            _PersonListStore = liststore;

            tv.Model           = liststore;
            tv.SearchColumn    = 0;
            tv.SearchEqualFunc = (model, col, key, iter) => {
                var person = (PersonModel)model.GetValue(iter, col);
                // Ladies and gentlemen welcome to C
                // 0 means it matched but 0 as bool is false. So if it matches
                // we have to return false. Still not clear? true is false and
                // false is true, weirdo! If you think this is retarded,
                // yes it is.
                return(!person.IdentityName.StartsWith(key, StringComparison.InvariantCultureIgnoreCase));
            };
            tv.EnableSearch   = true;
            tv.RowActivated  += new Gtk.RowActivatedHandler(OnPersonsRowActivated);
            tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent;

            // popup menu
            _PersonMenu = new Gtk.Menu();
            // don't loose the focus else we lose the selection too!
            // see OnPersonTreeViewFocusOutEvent()
            _PersonMenu.TakeFocus = false;
            _PersonMenu.Shown    += OnPersonMenuShown;

            _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent;
            _PersonTreeView.KeyPressEvent    += OnPersonTreeViewKeyPressEvent;
            // frame needed for events when selecting something in the treeview
            _PersonTreeViewFrame = new Gtk.Frame();
            _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent);
            _PersonTreeViewFrame.Add(sw);

            // topic
            // don't worry, ApplyConfig() will add us to the OutputVBox!
            _OutputVBox = new Gtk.VBox();

            _TopicTextView                        = new MessageTextView();
            _TopicTextView.Editable               = false;
            _TopicTextView.WrapMode               = Gtk.WrapMode.WordChar;
            _TopicScrolledWindow                  = new Gtk.ScrolledWindow();
            _TopicScrolledWindow.ShadowType       = Gtk.ShadowType.In;
            _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Never;
            _TopicScrolledWindow.Add(_TopicTextView);
            // make sure the topic is invisible and remains by default and
            // visible when a topic gets set
            _TopicScrolledWindow.ShowAll();
            _TopicScrolledWindow.Visible        = false;
            _TopicScrolledWindow.NoShowAll      = true;
            _TopicScrolledWindow.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) {
                // predict and set useful topic heigth
                int lineWidth, lineHeight;
                using (var layout = _TopicTextView.CreatePangoLayout("Test Topic")) {
                    layout.GetPixelSize(out lineWidth, out lineHeight);
                }
                var lineSpacing = _TopicTextView.PixelsAboveLines +
                                  _TopicTextView.PixelsBelowLines;
                var it       = _TopicTextView.Buffer.StartIter;
                int newLines = 1;
                // move to end of next visual line
                while (_TopicTextView.ForwardDisplayLineEnd(ref it))
                {
                    newLines++;
                    // calling ForwardDisplayLineEnd repeatedly stays on the same position
                    // therefor we move one cursor position further
                    it.ForwardCursorPosition();
                }
                newLines = Math.Min(newLines, 3);
                var bestSize = new Gtk.Requisition()
                {
                    Height = ((lineHeight + lineSpacing) * newLines) + 4
                };
                args.Requisition = bestSize;
            };

            Add(_OutputHPaned);

            //ApplyConfig(Frontend.UserConfig);

            ShowAll();
        }
예제 #6
0
 public TwitterGroupChatView(GroupChatModel groupChat) : base(groupChat)
 {
     Trace.Call(groupChat);
 }
예제 #7
0
        public static bool TryOpenChatLink(Uri link)
        {
            Trace.Call(link);

            if (Session == null)
            {
                return(false);
            }

            // supported:
            // smuxi://freenode/#smuxi
            // smuxi://freenode/#%23csharp (##csharp)
            // irc://#smuxi
            // irc://irc.oftc.net/
            // irc://irc.oftc.net/#smuxi
            // irc://irc.oftc.net:6667/#smuxi
            // not supported (yet):
            // smuxi:///meebey

            IProtocolManager manager = null;
            var linkPort             = link.Port;

            if (linkPort == -1)
            {
                switch (link.Scheme)
                {
                case "irc":
                    linkPort = 6667;
                    break;

                case "ircs":
                    linkPort = 6697;
                    break;
                }
            }
            // decode #%23csharp to ##csharp
            var linkChat = HttpUtility.UrlDecode(link.Fragment);

            if (String.IsNullOrEmpty(linkChat) && link.AbsolutePath.Length > 0)
            {
                linkChat = link.AbsolutePath.Substring(1);
            }

            var    linkProtocol = link.Scheme;
            var    linkHost     = link.Host;
            string linkNetwork  = null;

            if (!linkHost.Contains("."))
            {
                // this seems to be a network name
                linkNetwork = linkHost;
            }

            // find existing protocol chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats)
            {
                if (!(chatView is ProtocolChatView))
                {
                    continue;
                }
                var protocolChat = (ProtocolChatView)chatView;
                var host         = protocolChat.Host;
                var port         = protocolChat.Port;
                var network      = protocolChat.NetworkID;
                // Check first by network name with fallback to host+port.
                // The network name has to be checked against the NetworkID and
                // also ChatModel.ID as the user might have entered a different
                // network name in settings than the server does
                if (!String.IsNullOrEmpty(network) &&
                    (String.Compare(network, linkNetwork, true) == 0 ||
                     String.Compare(chatView.ID, linkNetwork, true) == 0))
                {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
                if (String.Compare(host, linkHost, true) == 0 &&
                    port == linkPort)
                {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
            }

            if (manager == null)
            {
                // only irc may autoconnect to a server
                switch (linkProtocol)
                {
                case "irc":
                case "ircs":
                case "smuxi":
                    break;

                default:
                    return(false);
                }
                ServerModel server = null;
                if (!String.IsNullOrEmpty(linkNetwork))
                {
                    // try to find a server with this network name and connect to it
                    var serverSettings = new ServerListController(UserConfig);
                    server = serverSettings.GetServerByNetwork(linkNetwork);
                    if (server == null)
                    {
                        // in case someone tried an unknown network
                        return(false);
                    }
                    // ignore OnConnectCommands
                    server.OnConnectCommands = null;
                }
                else if (!String.IsNullOrEmpty(linkHost))
                {
                    server = new ServerModel()
                    {
                        Protocol = linkProtocol,
                        Hostname = linkHost,
                        Port     = linkPort
                    };
                }
                if (server != null)
                {
                    manager = Session.Connect(server, FrontendManager);
                }
            }

            if (String.IsNullOrEmpty(linkChat))
            {
                return(true);
            }

            // switch to existing chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats)
            {
                if (manager != null && chatView.ProtocolManager != manager)
                {
                    continue;
                }
                if (String.Compare(chatView.ID, linkChat, true) == 0)
                {
                    MainWindow.ChatViewManager.CurrentChatView = chatView;
                    return(true);
                }
            }

            // join chat
            if (manager != null)
            {
                var chat = new GroupChatModel(linkChat, linkChat, null);
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        manager.OpenChat(FrontendManager, chat);
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
            return(true);
        }
예제 #8
0
        public GroupChatView(GroupChatModel groupChat) : base(groupChat)
        {
            Trace.Call(groupChat);

            _GroupChatModel = groupChat;

            // person list
            _OutputHPaned = new Gtk.HPaned();

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            _PersonScrolledWindow = sw;
            //sw.WidthRequest = 150;
            sw.HscrollbarPolicy = Gtk.PolicyType.Never;

            Gtk.TreeView tv = new Gtk.TreeView();
            _PersonTreeView = tv;
            //tv.CanFocus = false;
            tv.BorderWidth    = 0;
            tv.Selection.Mode = Gtk.SelectionMode.Multiple;
            sw.Add(tv);

            Gtk.TreeViewColumn   column;
            Gtk.CellRendererText cellr = new Gtk.CellRendererText();
            cellr.WidthChars     = 12;
            column               = new Gtk.TreeViewColumn(String.Empty, cellr);
            column.SortColumnId  = 0;
            column.Spacing       = 0;
            column.SortIndicator = false;
            column.Sizing        = Gtk.TreeViewColumnSizing.Autosize;
            column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName));
            tv.AppendColumn(column);
            _IdentityNameColumn = column;

            Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel));
            liststore.SetSortColumnId(0, Gtk.SortType.Ascending);
            liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore));
            _PersonListStore = liststore;

            tv.Model          = liststore;
            tv.RowActivated  += new Gtk.RowActivatedHandler(OnPersonsRowActivated);
            tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent;

            // popup menu
            _PersonMenu = new Gtk.Menu();
            // don't loose the focus else we lose the selection too!
            // see OnPersonTreeViewFocusOutEvent()
            _PersonMenu.TakeFocus = false;
            _PersonMenu.Shown    += OnPersonMenuShown;

            _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent;
            _PersonTreeView.KeyPressEvent    += OnPersonTreeViewKeyPressEvent;
            // frame needed for events when selecting something in the treeview
            _PersonTreeViewFrame = new Gtk.Frame();
            _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent);
            _PersonTreeViewFrame.Add(sw);

            // topic
            // don't worry, ApplyConfig() will add us to the OutputVBox!
            _OutputVBox = new Gtk.VBox();

            _TopicTextView                  = new MessageTextView();
            _TopicTextView.Editable         = false;
            _TopicTextView.WrapMode         = Gtk.WrapMode.WordChar;
            _TopicScrolledWindow            = new Gtk.ScrolledWindow();
            _TopicScrolledWindow.ShadowType = Gtk.ShadowType.In;
            // when using PolicyType.Never, it will try to grow but never shrinks!
            _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Automatic;
            _TopicScrolledWindow.VscrollbarPolicy = Gtk.PolicyType.Automatic;
            _TopicScrolledWindow.Add(_TopicTextView);
            // make sure the topic is invisible and remains by default and
            // visible when a topic gets set
            _TopicScrolledWindow.ShowAll();
            _TopicScrolledWindow.Visible   = false;
            _TopicScrolledWindow.NoShowAll = true;

            Add(_OutputHPaned);

            //ApplyConfig(Frontend.UserConfig);

            ShowAll();
        }
예제 #9
0
        protected virtual void OnFindButtonClicked(object sender, System.EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                string nameFilter = f_NameEntry.Text.Trim();
                if (!(Frontend.EngineProtocolVersion >= new Version("0.8.1")) &&
                    String.IsNullOrEmpty(nameFilter))
                {
                    Gtk.MessageDialog md = new Gtk.MessageDialog(
                        this,
                        Gtk.DialogFlags.Modal,
                        Gtk.MessageType.Warning,
                        Gtk.ButtonsType.YesNo,
                        _("Searching for group chats without a filter is not " +
                          "recommended.  This may take a while, or may not " +
                          "work at all.\n" +
                          "Do you wish to continue?")
                        );
                    int result = md.Run();
                    md.Destroy();
                    if (result != (int)Gtk.ResponseType.Yes)
                    {
                        return;
                    }
                }

                f_ListStore.Clear();
                CancelFindThread();

                GroupChatModel filter = new GroupChatModel(null, nameFilter, null);
                f_FindThread = new Thread(new ThreadStart(delegate {
                    try {
                        Gtk.Application.Invoke(delegate {
                            GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
                        });

                        IList <GroupChatModel> chats = f_ProtocolManager.FindGroupChats(filter);

                        Gtk.Application.Invoke(delegate {
                            Gdk.Color bgColor = f_TreeView.Style.Background(Gtk.StateType.Normal);
                            foreach (GroupChatModel chat in chats)
                            {
                                f_ListStore.AppendValues(
                                    chat,
                                    chat.PersonCount,
                                    chat.Name,
                                    PangoTools.ToMarkup(chat.Topic, bgColor)
                                    );
                            }
                        });
                    } catch (ThreadAbortException) {
#if LOG4NET
                        f_Logger.Debug("FindThread aborted");
#endif
                        Thread.ResetAbort();
                    } catch (Exception ex) {
                        Frontend.ShowError(this, _("Error while fetching the list of group chats from the server."), ex);
                    } finally {
                        Gtk.Application.Invoke(delegate {
                            // if the dialog is gone the GdkWindow might be destroyed already
                            if (GdkWindow != null)
                            {
                                GdkWindow.Cursor = null;
                            }
                        });
                    }
                }));
                f_FindThread.IsBackground = true;
                f_FindThread.Start();
            } catch (Exception ex) {
                Frontend.ShowException(ex);
            }
        }
예제 #10
0
파일: MainWindow.cs 프로젝트: licnep/smuxi
        protected virtual void OnChatOpenChatButtonClicked(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                OpenChatDialog dialog = new OpenChatDialog(this);
                int            res    = dialog.Run();

                var chatView = Notebook.CurrentChatView;
                if (chatView == null)
                {
                    return;
                }

                // FIXME: REMOTING CALL
                var manager = chatView.ChatModel.ProtocolManager;
                if (manager == null)
                {
                    return;
                }
                ChatModel chat;
                switch (dialog.ChatType)
                {
                case ChatType.Group:
                    chat = new GroupChatModel(
                        dialog.ChatName,
                        dialog.ChatName,
                        null
                        );
                    break;

                case ChatType.Person:
                    chat = new PersonChatModel(
                        null,
                        dialog.ChatName,
                        dialog.ChatName,
                        null
                        );
                    break;

                default:
                    throw new ApplicationException(
                              String.Format(
                                  _("Unknown ChatType: {0}"),
                                  dialog.ChatType
                                  )
                              );
                }

                dialog.Destroy();
                if (res != (int)Gtk.ResponseType.Ok)
                {
                    return;
                }

                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        manager.OpenChat(Frontend.FrontendManager, chat);
                    } catch (Exception ex) {
                        Frontend.ShowException(this, ex);
                    }
                });
            } catch (Exception ex) {
                Frontend.ShowException(this, ex);
            }
        }
예제 #11
0
 public void RemovePersonFromGroupChat(GroupChatModel cpage, PersonModel user)
 {
     Trace.Call(cpage, user);
 }
예제 #12
0
        private void _NickCompletion()
        {
            int    position = SelectionStart;
            string text     = Text;
            string word;
            int    previous_space;
            int    next_space;

            // find the current word
            string temp;

            temp           = text.Substring(0, position);
            previous_space = temp.LastIndexOf(' ');
            next_space     = text.IndexOf(' ', position);

#if LOG4NET
            _Logger.Debug("previous_space: " + previous_space);
            _Logger.Debug("next_space: " + next_space);
#endif

            if (previous_space != -1 && next_space != -1)
            {
                // previous and next space exist
                word = text.Substring(previous_space + 1, next_space - previous_space - 1);
            }
            else if (previous_space != -1)
            {
                // previous space exist
                word = text.Substring(previous_space + 1);
            }
            else if (next_space != -1)
            {
                // next space exist
                word = text.Substring(0, next_space);
            }
            else
            {
                // no spaces
                word = text;
            }

            if (word == String.Empty)
            {
                return;
            }

            // find the possible nickname
            bool   found         = false;
            bool   partial_found = false;
            string nick          = null;
            //GroupChatModel cp = (GroupChatModel) Frontend.FrontendManager.CurrentChat;
            GroupChatModel cp = (GroupChatModel)_Notebook.CurrentChatView.ChatModel;
            if ((bool)Frontend.UserConfig["Interface/Entry/BashStyleCompletion"])
            {
                IList <string> result = cp.PersonLookupAll(word);
                if (result == null || result.Count == 0)
                {
                    // no match
                }
                else if (result.Count == 1)
                {
                    found = true;
                    nick  = result[0];
                }
                else if (result.Count >= 2)
                {
                    string[] nickArray = new string[result.Count];
                    result.CopyTo(nickArray, 0);
                    string nicks = String.Join(" ", nickArray, 1, nickArray.Length - 1);
                    Frontend.FrontendManager.AddTextToChat(cp, "-!- " + nicks);
                    found         = true;
                    partial_found = true;
                    nick          = result[0];
                }
            }
            else
            {
                PersonModel person = cp.PersonLookup(word);
                if (person != null)
                {
                    found = true;
                    nick  = person.IdentityName;
                }
            }

            if (found)
            {
                // put the found nickname in place
                if (previous_space != -1 && next_space != -1)
                {
                    // previous and next space exist
                    temp = text.Remove(previous_space + 1, word.Length);
                    temp = temp.Insert(previous_space + 1, nick);
                    Text = temp;
                    if (partial_found)
                    {
                        SelectionStart = previous_space + 1 + nick.Length;
                    }
                    else
                    {
                        SelectionStart = previous_space + 2 + nick.Length;
                    }
                }
                else if (previous_space != -1)
                {
                    // only previous space exist
                    temp = text.Remove(previous_space + 1, word.Length);
                    temp = temp.Insert(previous_space + 1, nick);
                    if (partial_found)
                    {
                        Text = temp;
                    }
                    else
                    {
                        Text = temp + " ";
                    }
                    SelectionStart = previous_space + 2 + nick.Length;
                }
                else if (next_space != -1)
                {
                    // only next space exist
                    temp = text.Remove(0, next_space + 1);
                    if (partial_found)
                    {
                        Text           = nick + " " + temp;
                        SelectionStart = nick.Length;
                    }
                    else
                    {
                        Text           = nick + (string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"] + " " + temp;
                        SelectionStart = nick.Length + 2;
                    }
                }
                else
                {
                    // no spaces
                    if (partial_found)
                    {
                        Text = nick;
                    }
                    else
                    {
                        Text = nick + (string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"] + " ";
                    }
                    SelectionStart = -1;
                }
            }
        }