~ubuntu-branches/debian/squeeze/f-spot/squeeze

« back to all changes in this revision

Viewing changes to dpap-sharp/DPAPBrowser/DPAPBrowser.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DPAPBrowser.cs
 
2
//
 
3
// Author:
 
4
// Andrzej Wytyczak-Partyka <iapart@gmail.com>
 
5
// Copyright (C) 2008 Andrzej Wytyczak-Partyka
 
6
//
 
7
// This program is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// This program is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
// GNU General Public License for more details.
 
16
// 
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with this program; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
//
 
21
//
 
22
 
 
23
using System;
 
24
using FSpot;
 
25
using FSpot.Extensions;
 
26
using FSpot.Utils;
 
27
using FSpot.Widgets;
 
28
 
 
29
using System.IO;
 
30
using DPAP;
 
31
using Gtk;
 
32
 
 
33
namespace DPAP {
 
34
        
 
35
        public class DPAPPageWidget : ScrolledWindow {
 
36
                TreeView tree;
 
37
                TreeStore list;
 
38
                ServiceDiscovery sd;
 
39
                Client client;
 
40
                
 
41
                public DPAPPageWidget ()
 
42
                {
 
43
                        Console.WriteLine ("DPAP Page widget ctor!");
 
44
                        tree = new TreeView ();
 
45
                        Add (tree);
 
46
                        TreeViewColumn albumColumn = new Gtk.TreeViewColumn ();
 
47
                        //albumColumn.Title = "album";
 
48
 
 
49
                        Gtk.CellRendererText albumNameCell = new Gtk.CellRendererText ();
 
50
                        albumNameCell.Visible = true;
 
51
                        albumColumn.PackStart (albumNameCell,false);
 
52
                        tree.AppendColumn (albumColumn);
 
53
 
 
54
                        list = new TreeStore (typeof (string));
 
55
                        tree.Model = list;
 
56
                        
 
57
                        albumColumn.AddAttribute (albumNameCell, "text", 0);
 
58
                
 
59
                        tree.Selection.Changed += OnSelectionChanged;
 
60
                        sd = new DPAP.ServiceDiscovery ();
 
61
                        sd.Found += OnServiceFound;
 
62
                        sd.Removed += OnServiceRemoved;
 
63
                        sd.Start ();    
 
64
                }
 
65
                
 
66
                private void OnSelectionChanged (object o, EventArgs args)
 
67
                {
 
68
                        Gtk.TreeSelection selection =  (Gtk.TreeSelection) o;
 
69
                        Gtk.TreeModel model;
 
70
                        Gtk.TreeIter iter;
 
71
                        string data;
 
72
                        if (selection.GetSelected (out model, out iter)) {
 
73
                                GLib.Value val = GLib.Value.Empty;
 
74
                model.GetValue (iter, 0, ref val);
 
75
                data = (string) val.Val;
 
76
                                
 
77
                                if (list.IterDepth (iter) == 0)
 
78
                                        Connect (data);
 
79
                                else
 
80
                                        ViewAlbum (data);
 
81
                val.Dispose ();
 
82
                        }
 
83
                        
 
84
                }
 
85
                
 
86
                private void ViewAlbum (string name)
 
87
                {
 
88
                        Console.WriteLine ("View Album !");
 
89
                        Database d = client.Databases [0];
 
90
                        
 
91
                        Directory.CreateDirectory ("/tmp/" + client.Databases [0].Name);
 
92
                        //Console.WriteLine ("Looking for album '" + name + "'");
 
93
                        foreach (DPAP.Album alb in d.Albums)
 
94
                        {
 
95
                                //Console.WriteLine ("\t -- album '" + alb.Name + "'");
 
96
                                if (!alb.Name.Equals (name)) 
 
97
                                        continue;
 
98
                                
 
99
                                Directory.CreateDirectory (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name);
 
100
                                foreach (DPAP.Photo ph in alb.Photos)
 
101
                                        if (ph != null)
 
102
                                                d.DownloadPhoto (ph, System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name + "/" + ph.FileName);
 
103
                                        
 
104
                                FSpot.Core.FindInstance ().View ( System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name);
 
105
                                break;
 
106
                        }
 
107
                        
 
108
                        
 
109
                }
 
110
                
 
111
                private void Connect (string svcName)
 
112
                {
 
113
                        Service service = sd.ServiceByName (svcName);
 
114
                        System.Console.WriteLine ("Connecting to {0} at {1}:{2}", service.Name, service.Address, service.Port);
 
115
        
 
116
                        client = new Client (service);
 
117
                        TreeIter iter;
 
118
                        list.GetIterFirst (out iter);
 
119
                        foreach (Database d in client.Databases){
 
120
                                
 
121
                        //      list.AppendValues (iter,d.Name);
 
122
                                Console.WriteLine ("Database " + d.Name);
 
123
                                
 
124
                                foreach (Album alb in d.Albums)
 
125
                                                list.AppendValues (iter, alb.Name);
 
126
                                
 
127
                        // Console.WriteLine ("\tAlbum: "+alb.Name + ", id=" + alb.getId () + " number of items:" + alb.Photos.Count);
 
128
                        // Console.WriteLine (d.Photos [0].FileName);
 
129
                                                                
 
130
                        }
 
131
                }
 
132
                
 
133
                private void OnServiceFound (object o, ServiceArgs args)
 
134
                {
 
135
                        Service service = args.Service;
 
136
                        Console.WriteLine ("ServiceFound " + service.Name);
 
137
                        if (service.Name.Equals (System.Environment.UserName + " f-spot photos")) return;
 
138
                        list.AppendValues (service.Name);
 
139
                        
 
140
/*                      System.Console.WriteLine ("Connecting to {0} at {1}:{2}", service.Name, service.Address, service.Port);
 
141
                    
 
142
                        //client.Logout ();
 
143
                        //Console.WriteLine ("Press <enter> to exit...");
 
144
*/
 
145
                        
 
146
                }
 
147
                
 
148
                private void OnServiceRemoved (object o, ServiceArgs args)
 
149
                {
 
150
                        Service service = args.Service;
 
151
                        Console.WriteLine ("Service removed " + service.Name);
 
152
                        TreeIter root = TreeIter.Zero;
 
153
                        TreeIter iter = TreeIter.Zero;
 
154
 
 
155
                        bool valid = tree.Model.GetIterFirst (out root);
 
156
 
 
157
                        while (valid) {
 
158
                                if(((String)tree.Model.GetValue(root,0)).Equals(service.Name))
 
159
                                        (tree.Model as TreeStore).Remove(ref root);
 
160
                                valid = tree.Model.IterNext (ref root);
 
161
                        }
 
162
                        if (Directory.Exists (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + service.Name))
 
163
                                Directory.Delete (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + service.Name, true);
 
164
                        
 
165
                }
 
166
        }
 
167
        
 
168
        public class DPAPBrowser : SidebarPage
 
169
        {
 
170
                //public DPAPPage () { }
 
171
                private static DPAPPageWidget widget;
 
172
                public DPAPBrowser () : base (new DPAPPageWidget (), "Shared items", "gtk-new") 
 
173
                {
 
174
                        Console.WriteLine ("Starting DPAP client...");          
 
175
                        widget = (DPAPPageWidget)SidebarWidget;
 
176
                }
 
177
                
 
178
                                
 
179
        }
 
180
        
 
181
}