Permalink
Browse files

adds basic support for private messages

  • Loading branch information...
1 parent c17f98e commit 1c3188f9365ad0c621e0170800834912b44a23fe @schwarz committed Apr 15, 2012
@@ -33,8 +33,8 @@ namespace Handle.WPF.Converters
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
- using Caliburn.Micro;
using System.Windows.Media;
+ using Caliburn.Micro;
/// <summary>
/// Represents a concrete ValueConverter to convert strings, possibly containing links, to TextBlocks
@@ -145,6 +145,9 @@
<Compile Include="INotificationProvider.cs" />
<Compile Include="IProgressService.cs" />
<Compile Include="IrcChannelUserComparer.cs" />
+ <Compile Include="Views\IrcPrivateConversationView.xaml.cs">
+ <DependentUpon>IrcPrivateConversationView.xaml</DependentUpon>
+ </Compile>
<Compile Include="MessageFilterEventArgs.cs" />
<Compile Include="MessageLevels.cs" />
<Compile Include="Models\ExtendedSoundPlayer.cs">
@@ -155,6 +158,7 @@
<Compile Include="Models\TaskbarBlinkProvider.cs" />
<Compile Include="Models\ToastProvider.cs" />
<Compile Include="ProgressService.cs" />
+ <Compile Include="ViewModels\IrcPrivateConversationViewModel.cs" />
<Compile Include="ViewModels\NetworkQuickConnectViewModel.cs" />
<Compile Include="ViewModels\NotificationToastViewModel.cs" />
<Compile Include="Views\NetworkQuickConnectView.xaml.cs">
@@ -261,6 +265,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="Views\IrcPrivateConversationView.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Views\NetworkQuickConnectView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -31,7 +31,7 @@ namespace Handle.WPF
public enum MessageLevels
{
Public,
- Message,
+ Private,
Join,
Part,
Highlight,
@@ -75,6 +75,7 @@ public IrcNetworkViewModel(Network network, Settings settings)
this.Client = new IrcClient();
this.Client.Registered += this.clientRegistered;
+
// TODO Display Popup
this.Client.ConnectFailed += delegate(object sender, IrcErrorEventArgs e)
{
@@ -94,6 +95,27 @@ public IrcNetworkViewModel(Network network, Settings settings)
}
}
+ private void localUserMessageReceived(object sender, IrcMessageEventArgs e)
+ {
+ IrcPrivateConversationViewModel ipcvm = null;
+ foreach (var item in this.Items)
+ {
+ if (item.DisplayName == e.Source.Name)
+ {
+ ipcvm = item;
+ }
+ }
+
+ if (ipcvm == null)
+ {
+ ipcvm = new IrcPrivateConversationViewModel(e.Source, this.Client, this.Settings);
+ this.Items.Add(ipcvm);
+ ipcvm.Messages.Add(new Message(e.Text,
+ DateTime.Now.ToString(this.Settings.TimestampFormat),
+ e.Source.Name, MessageLevels.Private));
+ }
+ }
+
private void clientRegistered(object sender, EventArgs e)
{
this.Client.LocalUser.JoinedChannel += this.localUserJoinedChannel;
@@ -102,6 +124,7 @@ private void clientRegistered(object sender, EventArgs e)
istvm.Parent = this;
istvm.Settings = this.Settings;
istvm.JoinChannelClicked += this.JoinChannel;
+ this.Client.LocalUser.MessageReceived += this.localUserMessageReceived;
this.Items.Add(istvm);
}
@@ -0,0 +1,109 @@
+// -----------------------------------------------------------------------
+// <copyright file="IrcPrivateConversationViewModel.cs" company="">
+// Copyright (c) 2011-2012 Bernhard Schwarz, Florian Lembeck
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Handle.WPF
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Caliburn.Micro;
+ using IrcDotNet;
+
+ /// <summary>
+ /// TODO: Update summary.
+ /// </summary>
+ public class IrcPrivateConversationViewModel : ViewModelBase
+ {
+ public dynamic User { get; set; }
+ private IrcClient client;
+ public BindableCollection<Message> Messages { get; set; }
+ public bool Closable { get; set; }
+
+ private string message;
+
+ public string Message
+ {
+ get
+ {
+ return this.message;
+ }
+ set
+ {
+ this.message = value;
+ NotifyOfPropertyChange(() => this.Message);
+ NotifyOfPropertyChange(() => this.CanSend);
+ }
+ }
+
+ public IrcPrivateConversationViewModel(dynamic user, IrcClient client, Settings settings)
+ {
+ this.Settings = settings;
+ this.User = user;
+ this.client = client;
+ this.DisplayName = user.NickName;
+ this.Messages = new BindableCollection<Message>();
+ this.Closable = true;
+ // TODO
+ this.client.LocalUser.MessageReceived += this.messageReceived;
+ }
+
+ private void messageReceived(object sender, IrcMessageEventArgs e)
+ {
+ this.Messages.Add(new Message(e.Text,
+ DateTime.Now.ToString(this.Settings.TimestampFormat),
+ e.Source.Name, MessageLevels.Private));
+
+ }
+
+ public bool CanSend
+ {
+ get
+ {
+ return !string.IsNullOrWhiteSpace(this.Message);
+ }
+ }
+
+ public void Send()
+ {
+ this.client.LocalUser.SendMessage(this.User, this.Message);
+ this.Messages.Add(new Message(this.Message,
+ DateTime.Now.ToString(this.Settings.TimestampFormat),
+ this.client.LocalUser.NickName, MessageLevels.Private));
+ this.Message = string.Empty;
+ }
+
+ protected override void OnDeactivate(bool close)
+ {
+ // Assuming this is correct
+ if (close)
+ {
+ this.client.LocalUser.MessageReceived -= this.messageReceived;
+ Console.WriteLine("I'm closing! (" + this.DisplayName + ")");
+ }
+ base.OnDeactivate(close);
+ }
+ }
+}
@@ -0,0 +1,57 @@
+<UserControl x:Class="Handle.WPF.IrcPrivateConversationView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:cal="http://www.caliburnproject.org"
+ xmlns:Converters="clr-namespace:Handle.WPF.Converters"
+ mc:Ignorable="d"
+ d:DesignHeight="300" d:DesignWidth="300">
+ <UserControl.Resources>
+ <Converters:MessageConverter x:Key="messageConverter"/>
+ </UserControl.Resources>
+
+ <Grid x:Name="MainGrid">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*"/>
+ <RowDefinition Height="Auto"/>
+ </Grid.RowDefinitions>
+
+ <!-- Messages -->
+ <ScrollViewer Grid.Row="0" x:Name="MessagesScrollViewer">
+ <StackPanel>
+ <ItemsControl x:Name="Messages" FontFamily="{Binding Settings.FontFamily}" FontSize="{Binding Settings.FontSize}">
+ <ItemsControl.ItemTemplate>
+ <DataTemplate>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto"/>
+ <ColumnDefinition Width="Auto"/>
+ <ColumnDefinition Width="*"/>
+ </Grid.ColumnDefinitions>
+
+ <TextBlock Grid.Column="0" Text="{Binding Received}"/>
+ <TextBlock Grid.Column="1" Margin="5,0,0,0" Text="{Binding Sender}"/>
+ <ContentControl Grid.Column="2" Margin="5,0,0,0" Content="{Binding Converter={StaticResource messageConverter}}"/>
+ </Grid>
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
+ </StackPanel>
+ </ScrollViewer>
+
+ <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
+ <Image Height="35" cal:Message.Attach="[Event MouseLeftButtonUp] = [Action OpenContextMenu]" ToolTip="Connect to network or channel"
+ Source="/Handle.WPF;component/Images/add_small.png" Margin="2" Opacity="0.6">
+ <Image.ContextMenu>
+ <ContextMenu x:Name="CoMenu">
+ <MenuItem x:Name="JoinChannel" Header="Channel" cal:Message.Attach="[Event Click] = [Action JoinChannel]"/>
+ <MenuItem x:Name="JoinNetwork" Header="Network" cal:Message.Attach="[Event Click] = [Action JoinNetwork]"/>
+ </ContextMenu>
+ </Image.ContextMenu>
+ </Image>
+ <TextBox x:Name="Message" Width="300" Height="30"/>
+ <Image Height="35" cal:Message.Attach="[Event MouseLeftButtonUp] = [Action Send]" ToolTip="Send Message" Source="/Handle.WPF;component/Images/message.png" Margin="2" Opacity="0.6"/>
+ </StackPanel>
+ </Grid>
+</UserControl>
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Handle.WPF
+{
+ /// <summary>
+ /// Interaction logic for IrcPrivateConversationView.xaml
+ /// </summary>
+ public partial class IrcPrivateConversationView : UserControl
+ {
+ public IrcPrivateConversationView()
+ {
+ InitializeComponent();
+ }
+ }
+}

0 comments on commit 1c3188f

Please sign in to comment.