[blam/gtk-builder: 3/3] New GtkBuilder skeleton



commit dd7332d3e1b50f7c77d078e2f33b0b71d12030a4
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Fri Mar 22 18:15:19 2013 +0100

    New GtkBuilder skeleton
    
    Start migrating to a new UI based on GtkBuilder, looser coupling
    between the components and less global signal sending.
    
    Currently the new UI has the bare minimum to work and show the feeds,
    items and their main contents.

 blam.csproj              |    9 +-
 src/Blam.cs              |  103 ++++++++++++++++
 src/BuilderExtensions.cs |   14 +++
 src/ItemList.cs          |   73 ++++++++++++
 src/ItemView.cs          |   31 +++++
 src/MainWindow.cs        |   18 +++
 src/Makefile.am          |    2 +
 src/blam.ui              |  290 ++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 538 insertions(+), 2 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index 4fddb30..475cde5 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -7,10 +7,10 @@
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{4E407663-2362-4FCD-BC45-A772920BB32F}</ProjectGuid>
     <OutputType>WinExe</OutputType>
-    <RootNamespace>Imendio.Blam</RootNamespace>
+    <RootNamespace>Blam</RootNamespace>
     <AssemblyName>blam</AssemblyName>
     <ReleaseVersion>1.9.10</ReleaseVersion>
-    <StartupObject>Imendio.Blam.Application</StartupObject>
+    <StartupObject>Blam.Blam</StartupObject>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <DebugSymbols>True</DebugSymbols>
@@ -108,6 +108,8 @@
     <Compile Include="gtk-gui\generated.cs" />
     <Compile Include="gtk-gui\Imendio.Blam.AddChannelDialog.cs" />
     <Compile Include="src\AddChannelDialog.cs" />
+    <Compile Include="src\Blam.cs" />
+    <Compile Include="src\BuilderExtensions.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
@@ -116,6 +118,9 @@
     <None Include="src\Makefile.am" />
     <None Include="src\Makefile.in" />
     <None Include="configure.in" />
+    <None Include="src\blam.exe.config">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="src\blam.glade">
diff --git a/src/Blam.cs b/src/Blam.cs
new file mode 100644
index 0000000..8b216a3
--- /dev/null
+++ b/src/Blam.cs
@@ -0,0 +1,103 @@
+using System;
+using Gtk;
+using ChannelCollection = Imendio.Blam.ChannelCollection;
+using ChannelList = Imendio.Blam.ChannelList;
+using Defines = Imendio.Blam.Defines;
+
+namespace Blam
+{
+       using Channel = Imendio.Blam.Channel;
+
+       public class BlamApplication
+       {
+               Window MainWindow;
+               ItemList ItemList;
+               ChannelList FeedList;
+               ItemView ItemView;
+
+               ScrolledWindow FeedListSw;
+               ScrolledWindow ItemListSw;
+               ScrolledWindow ItemViewSw;
+
+               ChannelCollection channels;
+
+               public BlamApplication()
+               {
+                       var bld = new Builder();
+                       bld.AddFromFile("/home/carlos/progs/blam/blam/src/blam.ui");
+
+                       MainWindow = bld.GetObject<Window>("main-window");
+                       MainWindow.DeleteEvent += OnDelete;
+
+                       channels = ChannelCollection.LoadFromFile (Defines.APP_HOMEDIR + "/collection.xml");
+                       FeedListSw = bld.GetObject<ScrolledWindow>("feed-list-scroll");
+                       var FeedList = new ChannelList(channels.Channels, channels.Groups);
+                       FeedListSw.Child = FeedList;
+
+                       ItemList = new ItemList();
+                       ItemListSw = bld.GetObject<ScrolledWindow>("item-list-scroll");
+                       ItemListSw.Child = ItemList;
+
+                       ItemView = new ItemView();
+                       ItemViewSw = bld.GetObject<ScrolledWindow>("item-view-scroll");
+                       ItemViewSw.Child = ItemView;
+
+                       ItemList.Selection.Changed += OnItemChange;
+                       FeedList.Selection.Changed += OnFeedChange;
+               }
+
+               public void Run()
+               {
+                       MainWindow.ShowAll();
+                       Application.Run();
+               }
+
+               void OnDelete(object sender, DeleteEventArgs args)
+               {
+                       Application.Quit();
+                       args.RetVal = true;
+               }
+
+               void OnFeedChange(object obj, EventArgs args)
+               {
+                       TreeSelection selection = (TreeSelection)obj;
+                       TreeIter      iter;
+                       TreeModel     model;
+                       Channel      channel;
+
+                       if (!selection.GetSelected(out model, out iter))
+                               return;
+
+                       channel = model.GetValue(iter, 0) as Channel;
+                       ItemList.Channel = channel;
+               }
+
+               void OnItemChange(object obj, EventArgs args)
+               {
+                       TreeSelection selection = (TreeSelection) obj;
+                       TreeIter iter;
+                       TreeModel model;
+                       Imendio.Blam.Item item;
+
+                       if (!selection.GetSelected (out model, out iter)) {
+                               return;
+                       }
+
+                       item = (Imendio.Blam.Item) model.GetValue (iter, 0);
+                       ItemView.Item = item;
+                       //item.Unread = false;
+               }
+       }
+
+       public class Blam
+       {
+
+               public static void Main(string[] args)
+               {
+                       Application.Init("blam", ref args);
+
+                       new BlamApplication().Run();
+               }
+       }
+}
+
diff --git a/src/BuilderExtensions.cs b/src/BuilderExtensions.cs
new file mode 100644
index 0000000..13ccc5d
--- /dev/null
+++ b/src/BuilderExtensions.cs
@@ -0,0 +1,14 @@
+using System;
+using Gtk;
+using GLib;
+
+namespace Blam
+{
+       public static class BuilderExtensions
+       {
+               public static T GetObject<T>(this Builder builder, string name) where T: GLib.Object
+               {
+                       return (T) builder.GetObject(name);
+               }
+       }
+}
diff --git a/src/ItemList.cs b/src/ItemList.cs
index 8c096ba..44135ff 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -14,6 +14,79 @@ using System;
 using System.Collections;
 using System.ServiceModel.Syndication;
 
+namespace Blam
+{
+       using Channel = Imendio.Blam.Channel;
+       using ItemView = Imendio.Blam.ItemView;
+       using Item = Imendio.Blam.Item;
+       using ItemStore = Imendio.Blam.ItemStore;
+
+       public delegate void OnChange(Item item);
+
+       public class ItemList : Gtk.TreeView
+       {
+               public Channel Channel {
+                       get {
+                               return current;
+                       }
+                       set {
+                               current = value;
+                               UpdateList();
+                       }
+               }
+
+               Channel current;
+               TreeViewColumn column;
+
+               public event OnChange OnChangeEvent;
+
+               public ItemList()
+               {
+                       column = new TreeViewColumn();
+                       var renderer = new CellRendererText();
+                       column.PackStart(renderer, true);
+                       column.SetCellDataFunc(renderer, CellDataFunc);
+                       AppendColumn(column);
+
+                       this.Model = new ListStore (typeof(Imendio.Blam.Item));
+                       this.HeadersVisible = false;
+
+               }
+
+               void CellDataFunc (TreeViewColumn col, CellRenderer _cell, TreeModel model, TreeIter iter)
+               {
+                       Item item = model.GetValue(iter, 0) as Item;
+
+                       CellRendererText cell = _cell as CellRendererText;
+                       var weight = item.Unread ? Pango.Weight.Bold : Pango.Weight.Normal;
+                       var text = (item.Title as TextSyndicationContent).Text.Trim();
+
+                       cell.Text = Imendio.Blam.HtmlUtils.Unescape(text);
+                       cell.Weight = (int)weight;
+                       cell.Ellipsize = Pango.EllipsizeMode.End;
+               }
+
+               void UpdateList()
+               {
+                       if (current == null)
+                               return;
+
+                       var list = Model as ListStore;
+                       var store = ItemStore.GetInstance();
+
+                       list.Clear();
+                       foreach(string id in current.ItemList){
+                               if (id == null)
+                                       continue;
+
+                               list.AppendValues(store.Get(id));
+                       }
+               }
+
+
+       }
+}
+
 namespace Imendio.Blam {
     
        public class ItemList : Gtk.TreeView {
diff --git a/src/ItemView.cs b/src/ItemView.cs
index 8ae1400..d57d268 100644
--- a/src/ItemView.cs
+++ b/src/ItemView.cs
@@ -20,6 +20,37 @@ using System.Net;
 using System.Text;
 using System.ServiceModel.Syndication;
 
+namespace Blam
+{
+       using Item = Imendio.Blam.Item;
+       using Defines = Imendio.Blam.Defines;
+       public class ItemView : WebKit.WebView
+       {
+               Item current;
+
+               public Item Item {
+                       get {
+                               return current;
+                       }
+                       set {
+                               current = value;
+                               UpdateView();
+                       }
+               }
+
+               public ItemView() : base()
+               {
+               }
+
+               void UpdateView()
+               {
+                       string text = current.Summary != null ? current.Summary.Text
+                               : current.Content != null ? (current.Content as TextSyndicationContent).Text 
: null;
+                       LoadString(text, null, null, Defines.APP_DATADIR);
+               }
+       }
+}
+
 namespace Imendio.Blam {
     public class ItemView : Gtk.EventBox {
         private WebView webView;
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
new file mode 100644
index 0000000..b5a96de
--- /dev/null
+++ b/src/MainWindow.cs
@@ -0,0 +1,18 @@
+using System;
+using Gtk;
+
+namespace Blam
+{
+       public class MainWindow
+       {
+               [Gtk.Builder.Object]Window Window;
+
+               public MainWindow(Builder bld)
+               {
+                       Window = (Window)bld.GetObject("main-window");
+                       Window.ShowAll();
+
+               }
+       }
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 80dc1b6..442f99b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,7 +13,9 @@ ASSEMBLIES = \
             -r:System.ServiceModel
 
 BLAM_CSFILES = Application.cs \
+              BuilderExtensions.cs \
               AddChannelDialog.cs \
+              Blam.cs \
               ChannelDialog.cs \
               Channel.cs \
               ChannelCollection.cs \
diff --git a/src/blam.ui b/src/blam.ui
new file mode 100644
index 0000000..39830ef
--- /dev/null
+++ b/src/blam.ui
@@ -0,0 +1,290 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.24"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="main-window">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkVBox" id="main-cotnainer">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkMenuBar" id="menubar">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkMenuItem" id="menuitem1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_File</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem1">
+                        <property name="label">gtk-new</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem2">
+                        <property name="label">gtk-open</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem3">
+                        <property name="label">gtk-save</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem4">
+                        <property name="label">gtk-save-as</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem5">
+                        <property name="label">gtk-quit</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem6">
+                        <property name="label">gtk-cut</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem7">
+                        <property name="label">gtk-copy</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem8">
+                        <property name="label">gtk-paste</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem9">
+                        <property name="label">gtk-delete</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_View</property>
+                <property name="use_underline">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="label" translatable="yes">_Help</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem10">
+                        <property name="label">gtk-about</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHPaned" id="hpaned1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <child>
+              <object class="GtkVBox" id="vbox1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="feed-list-scroll">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">automatic</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="refresh-all">
+                    <property name="label">gtk-refresh</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_stock">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="resize">False</property>
+                <property name="shrink">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVPaned" id="vpaned1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="item-list-scroll">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">automatic</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="resize">False</property>
+                    <property name="shrink">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow" id="item-view-scroll">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hscrollbar_policy">automatic</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="resize">True</property>
+                    <property name="shrink">True</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="resize">True</property>
+                <property name="shrink">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkStatusbar" id="statusbar">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">2</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]