-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/send chatstates #97
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Smuxi - Smart MUltipleXed Irc | ||
// | ||
// Copyright (c) 2013 oliver | ||
// | ||
// Full GPL License: <http://www.gnu.org/licenses/gpl.txt> | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation; either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
using System; | ||
|
||
namespace Smuxi.Engine | ||
{ | ||
public enum ChatState { | ||
// after sending a message or w/o any state | ||
Active, | ||
// this chat window is not the active one | ||
Inactive, | ||
// is typing right now | ||
Composing, | ||
// was typing but stopped | ||
Paused, | ||
// the chat window has been closed | ||
Gone | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,15 @@ public Entry(ChatViewManager chatViewManager) | |
Activated += _OnActivated; | ||
KeyPressEvent += new Gtk.KeyPressEventHandler(_OnKeyPress); | ||
PasteClipboard += _OnClipboardPasted; | ||
|
||
Buffer.Changed += delegate { | ||
if (Buffer.Text.Length == 0) { | ||
return; | ||
} | ||
SetChatState(ChatState.Composing); | ||
}; | ||
|
||
LastChatState = ChatState.Gone; | ||
} | ||
|
||
public void UpdateHistoryChangedLine() | ||
|
@@ -464,6 +473,61 @@ protected virtual void ProcessKey(Gtk.KeyPressEventArgs e) | |
} | ||
} | ||
|
||
ChatState LastChatState { get; set; } | ||
DateTime LastChatStateCall { get; set; } | ||
bool ComposingTimeoutActive { get; set; } | ||
|
||
bool ChatStateComposingTimeout() | ||
{ | ||
if (LastChatState != ChatState.Composing) { | ||
ComposingTimeoutActive = false; | ||
return false; | ||
} | ||
var msleft = (LastChatStateCall + TimeSpan.FromSeconds(2)) - DateTime.Now; | ||
if (msleft > TimeSpan.Zero) { | ||
GLib.Timeout.Add((uint)msleft.Milliseconds, ChatStateComposingTimeout); | ||
return false; | ||
} | ||
SetChatState(ChatState.Paused); | ||
ComposingTimeoutActive = false; | ||
return false; | ||
} | ||
|
||
public void SetChatState(ChatState type) | ||
{ | ||
if (Frontend.EngineVersion < new Version(0, 9, 1)) { | ||
return; | ||
} | ||
var chatView = ChatViewManager.CurrentChatView as PersonChatView; | ||
if (chatView == null) { | ||
return; | ||
} | ||
|
||
if (type == ChatState.Composing) { | ||
LastChatStateCall = DateTime.Now; | ||
} | ||
if (LastChatState == type) { | ||
// no duplication | ||
return; | ||
} | ||
LastChatState = type; | ||
var protocol = Frontend.FrontendManager.CurrentProtocolManager; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a remoting call, but what is the purpose here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh getting the ProtocolManager of the current chat view. This needs to be done with local state of ChatViewManager. Doesnt ChatView has ProtocolManage property these days? |
||
if (protocol == null) { | ||
return; | ||
} | ||
|
||
if (type == ChatState.Composing) { | ||
if (!ComposingTimeoutActive) { | ||
ComposingTimeoutActive = true; | ||
GLib.Timeout.Add(2000, ChatStateComposingTimeout); | ||
} | ||
} | ||
|
||
protocol.SetChatState(Frontend.FrontendManager, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remoting call, use background thread. |
||
chatView.PersonChatModel, | ||
type); | ||
} | ||
|
||
private void _OnActivated(object sender, EventArgs e) | ||
{ | ||
Trace.Call(sender, e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next feature release that could contain this feature is 0.10, thus this should be < 0, 10 (0.9.1 will be a bugfix release from the stable branch)