4
// Andrzej Wytyczak-Partyka <iapart@gmail.com>
5
// Copyright (C) 2008 Andrzej Wytyczak-Partyka
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.
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.
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
25
using FSpot.Extensions;
35
public class DPAPPageWidget : ScrolledWindow {
41
public DPAPPageWidget ()
43
Console.WriteLine ("DPAP Page widget ctor!");
44
tree = new TreeView ();
46
TreeViewColumn albumColumn = new Gtk.TreeViewColumn ();
47
//albumColumn.Title = "album";
49
Gtk.CellRendererText albumNameCell = new Gtk.CellRendererText ();
50
albumNameCell.Visible = true;
51
albumColumn.PackStart (albumNameCell,false);
52
tree.AppendColumn (albumColumn);
54
list = new TreeStore (typeof (string));
57
albumColumn.AddAttribute (albumNameCell, "text", 0);
59
tree.Selection.Changed += OnSelectionChanged;
60
sd = new DPAP.ServiceDiscovery ();
61
sd.Found += OnServiceFound;
62
sd.Removed += OnServiceRemoved;
66
private void OnSelectionChanged (object o, EventArgs args)
68
Gtk.TreeSelection selection = (Gtk.TreeSelection) o;
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;
77
if (list.IterDepth (iter) == 0)
86
private void ViewAlbum (string name)
88
Console.WriteLine ("View Album !");
89
Database d = client.Databases [0];
91
Directory.CreateDirectory ("/tmp/" + client.Databases [0].Name);
92
//Console.WriteLine ("Looking for album '" + name + "'");
93
foreach (DPAP.Album alb in d.Albums)
95
//Console.WriteLine ("\t -- album '" + alb.Name + "'");
96
if (!alb.Name.Equals (name))
99
Directory.CreateDirectory (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name);
100
foreach (DPAP.Photo ph in alb.Photos)
102
d.DownloadPhoto (ph, System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name + "/" + ph.FileName);
104
FSpot.Core.FindInstance ().View ( System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal) + "/.cache/DPAP/" + client.Name + "/" + alb.Name);
111
private void Connect (string svcName)
113
Service service = sd.ServiceByName (svcName);
114
System.Console.WriteLine ("Connecting to {0} at {1}:{2}", service.Name, service.Address, service.Port);
116
client = new Client (service);
118
list.GetIterFirst (out iter);
119
foreach (Database d in client.Databases){
121
// list.AppendValues (iter,d.Name);
122
Console.WriteLine ("Database " + d.Name);
124
foreach (Album alb in d.Albums)
125
list.AppendValues (iter, alb.Name);
127
// Console.WriteLine ("\tAlbum: "+alb.Name + ", id=" + alb.getId () + " number of items:" + alb.Photos.Count);
128
// Console.WriteLine (d.Photos [0].FileName);
133
private void OnServiceFound (object o, ServiceArgs args)
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);
140
/* System.Console.WriteLine ("Connecting to {0} at {1}:{2}", service.Name, service.Address, service.Port);
143
//Console.WriteLine ("Press <enter> to exit...");
148
private void OnServiceRemoved (object o, ServiceArgs args)
150
Service service = args.Service;
151
Console.WriteLine ("Service removed " + service.Name);
152
TreeIter root = TreeIter.Zero;
153
TreeIter iter = TreeIter.Zero;
155
bool valid = tree.Model.GetIterFirst (out root);
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);
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);
168
public class DPAPBrowser : SidebarPage
170
//public DPAPPage () { }
171
private static DPAPPageWidget widget;
172
public DPAPBrowser () : base (new DPAPPageWidget (), "Shared items", "gtk-new")
174
Console.WriteLine ("Starting DPAP client...");
175
widget = (DPAPPageWidget)SidebarWidget;