[Patch] Export to Original.
- From: Alessandro Gervaso <gervystar gervystar net>
- To: f-spot-list gnome org
- Subject: [Patch] Export to Original.
- Date: Fri, 21 Jan 2005 01:13:18 +0100
Here it is.
As I've told before I've had some trouble with the transfer-related
progress-bar and I don't think I have enough knowledge of the gnome-vfs
system to solve this.
So I hope that someone could make it better.
At this time the export module creates a local gallery, and exports it
to the chosen VFS location (i uploaded two galleries on a webdav
location) but the gui hangs here.
I attach the needed files.
Cheers
Alessandro.
P.S: the code isn't currently that clean ;-P
--
Gervystar - Alessandro Gervaso - gervystar gervystar net
Home page: http://www.gervystar.net/ - ICQ: 30482347
JID: gervystar actualize it
Pordenone LUG: http://www.lilliput.linux.it/ - Linux User #198264
Index: src/f-spot.glade
===================================================================
RCS file: /cvs/gnome/f-spot/src/f-spot.glade,v
retrieving revision 1.65
diff -r1.65 f-spot.glade
1624d1623
< <property name="icon_size">4</property>
1776d1774
< <property name="icon_size">4</property>
6214a6213,6221
> <widget class="GtkMenuItem" id="export_to_original">
> <property name="visible">True</property>
> <property name="label" translatable="yes">Export to _Original...</property>
> <property name="use_underline">True</property>
> <signal name="activate" handler="HandleExportToOriginal" last_modification_time="Tue, 18 Jan 2005 14:38:36 GMT"/>
> </widget>
> </child>
>
> <child>
6561c6568
< <property name="active">True</property>
---
> <property name="active">False</property>
7340d7346
< <property name="icon_size">4</property>
7962d7967
< <property name="icon_size">4</property>
8497a8503,8950
> <widget class="GtkDialog" id="original_export_dialog">
> <property name="title" translatable="yes">Export to Original</property>
> <property name="type">GTK_WINDOW_TOPLEVEL</property>
> <property name="window_position">GTK_WIN_POS_NONE</property>
> <property name="modal">False</property>
> <property name="resizable">True</property>
> <property name="destroy_with_parent">False</property>
> <property name="decorated">True</property>
> <property name="skip_taskbar_hint">False</property>
> <property name="skip_pager_hint">False</property>
> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
> <property name="has_separator">False</property>
>
> <child internal-child="vbox">
> <widget class="GtkVBox" id="vbox49">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">0</property>
>
> <child internal-child="action_area">
> <widget class="GtkHButtonBox" id="hbuttonbox8">
> <property name="visible">True</property>
> <property name="layout_style">GTK_BUTTONBOX_END</property>
>
> <child>
> <widget class="GtkButton" id="button15">
> <property name="visible">True</property>
> <property name="can_default">True</property>
> <property name="can_focus">True</property>
> <property name="label">gtk-cancel</property>
> <property name="use_stock">True</property>
> <property name="relief">GTK_RELIEF_NORMAL</property>
> <property name="focus_on_click">True</property>
> <property name="response_id">-6</property>
> </widget>
> </child>
>
> <child>
> <widget class="GtkButton" id="button16">
> <property name="visible">True</property>
> <property name="can_default">True</property>
> <property name="can_focus">True</property>
> <property name="label">gtk-ok</property>
> <property name="use_stock">True</property>
> <property name="relief">GTK_RELIEF_NORMAL</property>
> <property name="focus_on_click">True</property>
> <property name="response_id">-5</property>
> </widget>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">True</property>
> <property name="pack_type">GTK_PACK_END</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkHBox" id="hbox42">
> <property name="border_width">6</property>
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">0</property>
>
> <child>
> <widget class="GtkFrame" id="frame34">
> <property name="visible">True</property>
> <property name="label_xalign">0</property>
> <property name="label_yalign">0.5</property>
> <property name="shadow_type">GTK_SHADOW_NONE</property>
>
> <child>
> <widget class="GtkAlignment" id="alignment38">
> <property name="visible">True</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xscale">1</property>
> <property name="yscale">1</property>
> <property name="top_padding">0</property>
> <property name="bottom_padding">0</property>
> <property name="left_padding">12</property>
> <property name="right_padding">0</property>
>
> <child>
> <widget class="GtkScrolledWindow" id="thumb_scrolledwindow">
> <property name="width_request">180</property>
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
> <property name="shadow_type">GTK_SHADOW_IN</property>
> <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
>
> <child>
> <placeholder/>
> </child>
> </widget>
> </child>
> </widget>
> </child>
>
> <child>
> <widget class="GtkLabel" id="label128">
> <property name="visible">True</property>
> <property name="label" translatable="yes"><b>Photos</b></property>
> <property name="use_underline">False</property>
> <property name="use_markup">True</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="type">label_item</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkVBox" id="vbox50">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">6</property>
>
> <child>
> <widget class="GtkFrame" id="frame35">
> <property name="visible">True</property>
> <property name="label_xalign">0</property>
> <property name="label_yalign">0.5</property>
> <property name="shadow_type">GTK_SHADOW_NONE</property>
>
> <child>
> <widget class="GtkAlignment" id="alignment39">
> <property name="visible">True</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xscale">1</property>
> <property name="yscale">1</property>
> <property name="top_padding">0</property>
> <property name="bottom_padding">0</property>
> <property name="left_padding">12</property>
> <property name="right_padding">0</property>
>
> <child>
> <widget class="GtkVBox" id="vbox51">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">6</property>
>
> <child>
> <widget class="GtkHBox" id="hbox43">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">6</property>
>
> <child>
> <widget class="GtkLabel" id="label129">
> <property name="visible">True</property>
> <property name="label" translatable="yes">Uri:</property>
> <property name="use_underline">False</property>
> <property name="use_markup">False</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkEntry" id="uri_entry">
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="editable">True</property>
> <property name="visibility">True</property>
> <property name="max_length">0</property>
> <property name="text" translatable="yes"></property>
> <property name="has_frame">True</property>
> <property name="invisible_char">*</property>
> <property name="activates_default">False</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkCheckButton" id="open_check">
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="label" translatable="yes">Open destination when done exporting.</property>
> <property name="use_underline">True</property>
> <property name="relief">GTK_RELIEF_NORMAL</property>
> <property name="focus_on_click">True</property>
> <property name="active">True</property>
> <property name="inconsistent">False</property>
> <property name="draw_indicator">True</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkLabel" id="label130">
> <property name="visible">True</property>
> <property name="label" translatable="yes"></property>
> <property name="use_underline">False</property>
> <property name="use_markup">False</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
> </widget>
> </child>
> </widget>
> </child>
>
> <child>
> <widget class="GtkLabel" id="label131">
> <property name="visible">True</property>
> <property name="label" translatable="yes"><b>Destination</b></property>
> <property name="use_underline">False</property>
> <property name="use_markup">True</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="type">label_item</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkFrame" id="frame36">
> <property name="visible">True</property>
> <property name="label_xalign">0</property>
> <property name="label_yalign">0.5</property>
> <property name="shadow_type">GTK_SHADOW_NONE</property>
>
> <child>
> <widget class="GtkAlignment" id="alignment40">
> <property name="visible">True</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xscale">1</property>
> <property name="yscale">1</property>
> <property name="top_padding">0</property>
> <property name="bottom_padding">0</property>
> <property name="left_padding">12</property>
> <property name="right_padding">0</property>
>
> <child>
> <widget class="GtkVBox" id="vbox52">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">6</property>
>
> <child>
> <widget class="GtkHBox" id="hbox44">
> <property name="visible">True</property>
> <property name="homogeneous">False</property>
> <property name="spacing">0</property>
>
> <child>
> <widget class="GtkCheckButton" id="scale_check">
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="label" translatable="yes">Scale images to no larger than: </property>
> <property name="use_underline">True</property>
> <property name="relief">GTK_RELIEF_NORMAL</property>
> <property name="focus_on_click">True</property>
> <property name="active">False</property>
> <property name="inconsistent">True</property>
> <property name="draw_indicator">True</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">True</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkEntry" id="width_entry">
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="editable">True</property>
> <property name="visibility">True</property>
> <property name="max_length">3</property>
> <property name="text" translatable="yes"></property>
> <property name="has_frame">True</property>
> <property name="invisible_char">*</property>
> <property name="activates_default">False</property>
> <property name="width_chars">5</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkLabel" id="label132">
> <property name="visible">True</property>
> <property name="label" translatable="yes">x</property>
> <property name="use_underline">False</property>
> <property name="use_markup">False</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
>
> <child>
> <widget class="GtkEntry" id="height_entry">
> <property name="visible">True</property>
> <property name="can_focus">True</property>
> <property name="editable">True</property>
> <property name="visibility">True</property>
> <property name="max_length">0</property>
> <property name="text" translatable="yes"></property>
> <property name="has_frame">True</property>
> <property name="invisible_char">*</property>
> <property name="activates_default">False</property>
> <property name="width_chars">5</property>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
> </widget>
> </child>
> </widget>
> </child>
>
> <child>
> <widget class="GtkLabel" id="label133">
> <property name="visible">True</property>
> <property name="label" translatable="yes"><b>Style</b></property>
> <property name="use_underline">False</property>
> <property name="use_markup">True</property>
> <property name="justify">GTK_JUSTIFY_LEFT</property>
> <property name="wrap">False</property>
> <property name="selectable">False</property>
> <property name="xalign">0.5</property>
> <property name="yalign">0.5</property>
> <property name="xpad">0</property>
> <property name="ypad">0</property>
> </widget>
> <packing>
> <property name="type">label_item</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">False</property>
> <property name="fill">False</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
> </widget>
> <packing>
> <property name="padding">0</property>
> <property name="expand">True</property>
> <property name="fill">True</property>
> </packing>
> </child>
> </widget>
> </child>
> </widget>
>
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.148
diff -r1.148 MainWindow.cs
817a818,822
> void HandleExportToOriginal (object sender, EventArgs args)
> {
> new FSpot.OriginalExport (new FSpot.PhotoArray (SelectedPhotos ()));
> }
>
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/f-spot/src/Makefile.am,v
retrieving revision 1.8
diff -r1.8 Makefile.am
40a41
> $(srcdir)/OriginalExport.cs \
136a138
> /r:ICSharpCode.SharpZipLib \
/*
* Copyright (C) 2005 Alessandro Gervaso <gervystar gervystar net>
*
* 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.
*/
//This should be used to export the selected pics to an original gallery
//located on a VFS location.
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
namespace FSpot {
public class OriginalExport {
IPhotoCollection selection;
[Glade.Widget] Gtk.Dialog original_export_dialog;
[Glade.Widget] Gtk.ScrolledWindow thumb_scrolledwindow;
[Glade.Widget] Gtk.Entry uri_entry;
//[Glade.Widget] Gtk.CheckButton meta_check;
[Glade.Widget] Gtk.CheckButton scale_check;
[Glade.Widget] Gtk.CheckButton open_check;
[Glade.Widget] Gtk.Entry width_entry;
[Glade.Widget] Gtk.Entry height_entry;
Gnome.Vfs.Uri dest;
int photo_index;
bool open;
string gallery_path;
FSpot.ThreadProgressDialog progress_dialog;
System.Threading.Thread command_thread;
public OriginalExport (IPhotoCollection selection)
{
Gnome.Vfs.ModuleCallbackFullAuthentication auth = new Gnome.Vfs.ModuleCallbackFullAuthentication ();
auth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
auth.SetDefault ();
auth.Push ();
Gnome.Vfs.ModuleCallbackAuthentication mauth = new Gnome.Vfs.ModuleCallbackAuthentication ();
mauth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
mauth.SetDefault ();
mauth.Push ();
Gnome.Vfs.ModuleCallbackSaveAuthentication sauth = new Gnome.Vfs.ModuleCallbackSaveAuthentication ();
sauth.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleAuth);
sauth.SetDefault ();
sauth.Push ();
Gnome.Vfs.ModuleCallbackStatusMessage msg = new Gnome.Vfs.ModuleCallbackStatusMessage ();
msg.Callback += new Gnome.Vfs.ModuleCallbackHandler (HandleMsg);
msg.SetDefault ();
msg.Push ();
this.selection = selection;
// FIXME this xml file path should be be retrieved from a central location not hard coded there
Glade.XML xml = new Glade.XML (null, "f-spot.glade", "original_export_dialog", null);
xml.Autoconnect (this);
IconView view = new IconView (selection);
view.DisplayDates = false;
view.DisplayTags = false;
Dialog.Modal = false;
Dialog.TransientFor = null;
thumb_scrolledwindow.Add (view);
Dialog.ShowAll ();
//LoadHistory ();
Dialog.Response += HandleResponse;
}
public Gtk.Dialog Dialog {
get {
return this.original_export_dialog;
}
}
public void Upload ()
{
try {
OriginalGallery gallery = new OriginalGallery(selection);
//Console.WriteLine("Started!!!");
// set the tmpdir and the galleryname using the given properties
gallery.StartProcessing();
gallery.ScalingThread.Join();
this.gallery_path = gallery.GalleryPath;
//Console.WriteLine("Finished!!!");
} catch {}
try {
Dialog.Destroy ();
Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
Gnome.Vfs.Uri source = new Gnome.Vfs.Uri (gallery_path);
Gnome.Vfs.Uri target = dest.Clone();
target = target.AppendFileName(source.ExtractShortName ());
Console.WriteLine(target);
Gnome.Vfs.XferProgressCallback cb = new Gnome.Vfs.XferProgressCallback (Progress);
System.Console.WriteLine ("Xfering {0} to {1}", source.ToString (), target.ToString ());
result = Gnome.Vfs.Xfer.XferUri (source, target,
Gnome.Vfs.XferOptions.Default,
Gnome.Vfs.XferErrorMode.Abort,
Gnome.Vfs.XferOverwriteMode.Replace,
cb);
//foreach (Photo photo in selection.Photos) {
//Gnome.Vfs.Uri source = new Gnome.Vfs.Uri (photo.DefaultVersionUri.ToString ());
//Gnome.Vfs.Uri target = dest.Clone ();
//target = target.AppendFileName (source.ExtractShortName ());
//Gnome.Vfs.XferProgressCallback cb = new Gnome.Vfs.XferProgressCallback (Progress);
//System.Console.WriteLine ("Xfering {0} to {1}", source.ToString (), target.ToString ());
//progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Transfering picture \"{0}\""), photo.Name);
//progress_dialog.Fraction = photo_index / (double) selection.Photos.Length;
//progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
// photo_index, selection.Photos.Length);
//result = Gnome.Vfs.Xfer.XferUri (source, target,
// Gnome.Vfs.XferOptions.Default,
// Gnome.Vfs.XferErrorMode.Abort,
// Gnome.Vfs.XferOverwriteMode.Replace,
// cb);
//photo_index++;
//}
if (result == Gnome.Vfs.Result.Ok) {
progress_dialog.Message = Mono.Posix.Catalog.GetString ("Done Sending Photos");
progress_dialog.Fraction = 1.0;
progress_dialog.ProgressText = Mono.Posix.Catalog.GetString ("Transfer Complete");
progress_dialog.ButtonLabel = Gtk.Stock.Ok;
} else {
progress_dialog.ProgressText = result.ToString ();
progress_dialog.Message = Mono.Posix.Catalog.GetString ("Error While Transfering");
}
if (open && photo_index > 0)
Gnome.Url.Show (dest.ToString ());
} catch (System.Exception e) {
progress_dialog.Message = e.ToString ();
progress_dialog.ProgressText = Mono.Posix.Catalog.GetString ("Error Transfering");
}
}
private int Progress (Gnome.Vfs.XferProgressInfo info)
{
progress_dialog.ProgressText = info.Phase.ToString ();
if (info.BytesTotal > 0) {
progress_dialog.Fraction = info.BytesCopied / (double)info.BytesTotal;
}
switch (info.Status) {
case Gnome.Vfs.XferProgressStatus.Vfserror:
progress_dialog.Message = Mono.Posix.Catalog.GetString ("Error: Error while transfering, Aborting");
return (int)Gnome.Vfs.XferErrorAction.Abort;
case Gnome.Vfs.XferProgressStatus.Overwrite:
progress_dialog.ProgressText = Mono.Posix.Catalog.GetString ("Error: File Already Exists, Aborting");
return (int)Gnome.Vfs.XferOverwriteAction.Abort;
default:
return 1;
}
}
private void HandleMsg (Gnome.Vfs.ModuleCallback cb)
{
Gnome.Vfs.ModuleCallbackStatusMessage msg = cb as Gnome.Vfs.ModuleCallbackStatusMessage;
System.Console.WriteLine ("{0}", msg.Message);
}
private void HandleAuth (Gnome.Vfs.ModuleCallback cb)
{
Gnome.Vfs.ModuleCallbackFullAuthentication fcb = cb as Gnome.Vfs.ModuleCallbackFullAuthentication;
System.Console.Write ("Enter your username ({0}): ", fcb.Username);
string username = System.Console.ReadLine ();
System.Console.Write ("Enter your password : ");
string passwd = System.Console.ReadLine ();
if (username.Length > 0)
fcb.Username = username;
fcb.Password = passwd;
}
private void HandleResponse (object sender, Gtk.ResponseArgs args)
{
if (args.ResponseId != Gtk.ResponseType.Ok) {
Dialog.Destroy ();
return;
}
dest = new Gnome.Vfs.Uri (uri_entry.Text);
open = open_check.Active;
#if false
Upload ();
#else
command_thread = new System.Threading.Thread (new System.Threading.ThreadStart (Upload));
command_thread.Name = Mono.Posix.Catalog.GetString ("Transfering Pictures");
//command_thread.Start ();
//FIXME: get the files/dirs count in a cleaner way than (* 5 + 2(zip) + 9)
// selection * 5 (original, mq, lq, thumbs, comments)
// 2: zipfiles
// 9: directories + info.txt + .htaccess
// this should actually be 1 anyway, because we transfer just one dir
progress_dialog = new FSpot.ThreadProgressDialog (command_thread, //(selection.Photos.Length * 4) + 2 + 9);
1);
progress_dialog.Start ();
#endif
}
}
// This class will create a local gallery in a temporary location (e.g. /tmp)
class OriginalGallery
{
private IPhotoCollection selection;
private string gallery_name = "web-gallery";
private string gallery_path;
private string tmpdir = "temp";
private bool setmtime = false;
private int scale_index = 1;
private int photo_index = 1; //used to name files
FSpot.ThreadProgressDialog progress_dialog;
System.Threading.Thread command_thread;
public OriginalGallery (IPhotoCollection selection)
{
this.selection = selection;
}
public void StartProcessing()
{
MakeDirs();
CreateHtaccess();
CreateInfo();
command_thread = new System.Threading.Thread (new System.Threading.ThreadStart (StartAll));
command_thread.Name = Mono.Posix.Catalog.GetString ("Scaling Pictures");
//command_thread.Start ();
progress_dialog = new FSpot.ThreadProgressDialog (command_thread, (selection.Photos.Length * 4) + 2);
progress_dialog.Start ();
}
private void StartAll()
{
//FIXME: when used in a try statement, a System.NullReferenceException
// is thrown after completion.
//try {
foreach (Photo photo in selection.Photos) {
//System.Console.WriteLine(photo.Path);
CreateScaledImages(photo.Path);
//Console.WriteLine("Scaled: " + scale_index);
CopyHq(photo.Path);
//Console.WriteLine("Copied: " + scale_index);
CreateComments(photo.Path);
//Set the directory's mtime sa the oldest photo's one.
if (!setmtime)
{
try {
Directory.SetLastWriteTimeUtc(gallery_path, photo.Time);
setmtime = true;
} catch { setmtime = false; }
}
photo_index++;
}
CreateZipFile("mq");
CreateZipFile("hq");
progress_dialog.Message = Mono.Posix.Catalog.GetString ("Done Scaling Pictures");
progress_dialog.Fraction = 1.0;
progress_dialog.ProgressText = Mono.Posix.Catalog.GetString ("Scaling Complete");
progress_dialog.Destroy();
//progress_dialog.ButtonLabel = Gtk.Stock.Ok;
//} catch (System.Exception e) {
// progress_dialog.Message = Mono.Posix.Catalog.GetString ("Error Scaling Pictures");
//}
}
private void MakeDirs()
{
gallery_path = Global.HomeDirectory + Path.DirectorySeparatorChar
+ tmpdir + Path.DirectorySeparatorChar + gallery_name;
//FIXME: Create this with 0700 mode in the case it is placed in /tmp
try {
Directory.CreateDirectory(gallery_path);
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "thumbs");
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "lq");
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "mq");
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "hq");
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "comments");
Directory.CreateDirectory(gallery_path + Path.DirectorySeparatorChar + "zip");
} catch {
Console.WriteLine("Error in creating directory" + gallery_path);
}
}
private void CreateScaledImages (string photo_path)
{
Gdk.Pixbuf source_image = new Gdk.Pixbuf(photo_path);
float image_ratio = 0;
if (source_image.Height <= source_image.Width) {
image_ratio = source_image.Height / source_image.Width;
} else {
image_ratio = source_image.Width / source_image.Height;
}
progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Scaling Picture \"{0}\""), "img-" + photo_index + ".jpg");
progress_dialog.Fraction = scale_index / (double) ((selection.Photos.Length * 4) + 2);
progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
scale_index, (selection.Photos.Length * 4) + 2);
scale_index++;
//FIXME: set the jpeg quality to 75
//string[] quality = {"quality","75"};
// scale the images to different sizes
source_image.ScaleSimple(120, 90, Gdk.InterpType.Bilinear).Savev(
gallery_path + Path.DirectorySeparatorChar + "thumbs"
+ Path.DirectorySeparatorChar + "img-" + photo_index + ".jpg", "jpeg", null, null);
//low quality
progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Scaling Picture \"{0}\""), "img-" + photo_index + ".jpg");
progress_dialog.Fraction = scale_index / (double) ((selection.Photos.Length * 4) + 2);
progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
scale_index, (selection.Photos.Length * 4) + 2);
scale_index++;
source_image.ScaleSimple(640, 480, Gdk.InterpType.Bilinear).Savev(
gallery_path + Path.DirectorySeparatorChar + "lq"
+ Path.DirectorySeparatorChar + "img-" + photo_index + ".jpg", "jpeg", null, null);
//medium quality
progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Scaling Picture \"{0}\""), "img-" + photo_index + ".jpg");
progress_dialog.Fraction = scale_index / (double) ((selection.Photos.Length * 4) + 2);
progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
scale_index, (selection.Photos.Length * 4) + 2);
scale_index++;
source_image.ScaleSimple(800, 600, Gdk.InterpType.Bilinear).Savev(
gallery_path + Path.DirectorySeparatorChar + "mq"
+ Path.DirectorySeparatorChar + "img-" + photo_index + ".jpg", "jpeg", null, null);
source_image.Dispose();
}
private void CopyHq(string photo_path)
{
try
{
progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Copying Picture \"{0}\""), "img-" + photo_index + ".jpg");
progress_dialog.Fraction = scale_index / (double) ((selection.Photos.Length * 4) + 2);
progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
scale_index, (selection.Photos.Length * 4) + 2);
scale_index++;
File.Copy(photo_path, gallery_path + Path.DirectorySeparatorChar
+ "hq" + Path.DirectorySeparatorChar + "img-" + photo_index + ".jpg", true);
} catch {}
}
private void CreateComments(string photo_path)
{
StreamWriter comment = File.CreateText(gallery_path + Path.DirectorySeparatorChar
+ "comments" + Path.DirectorySeparatorChar + "img-" + photo_index + ".txt");
comment.WriteLine("<span>image " + photo_index + "</span>\n");
comment.Close();
}
private void CreateZipFile(string img_quality)
{
progress_dialog.Message = System.String.Format (Mono.Posix.Catalog.GetString ("Creating Zip Files \"{0}\""), img_quality);
progress_dialog.Fraction = scale_index / (double) ((selection.Photos.Length * 4) + 2);
progress_dialog.ProgressText = System.String.Format (Mono.Posix.Catalog.GetString ("{0} of {1}"),
scale_index, (selection.Photos.Length * 4) + 2);
//Console.WriteLine("created" + img_quality + "zip" + " " + scale_index);
scale_index++;
string[] filenames = Directory.GetFiles(gallery_path + Path.DirectorySeparatorChar + img_quality);
Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(File.Create(gallery_path
+ Path.DirectorySeparatorChar + "zip" + Path.DirectorySeparatorChar
+ img_quality + ".zip"));
s.SetLevel(0);
foreach (string file in filenames) {
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
// set Size and the crc, because the information
// about the size and crc should be stored in the header
// if it is not set it is automatically written in the footer.
// (in this case size == crc == -1 in the header)
// Some ZIP programs have problems with zip files that don't store
// the size and crc in the header.
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
private void CreateHtaccess()
{
StreamWriter htaccess = File.CreateText(gallery_path + Path.DirectorySeparatorChar + ".htaccess");
htaccess.Write("<Files info.txt>\n\tdeny from all\n</Files>\n");
htaccess.Close();
}
private void CreateInfo()
{
//Console.WriteLine(selection.Photos[0].Time.Date.ToString ("yyyy-MM-dd"));
StreamWriter info = File.CreateText(gallery_path + Path.DirectorySeparatorChar + "info.txt");
info.WriteLine("date|" + selection.Photos[0].Time.Date.ToString ("yyyy-MM-dd"));
info.Close();
}
// This is provided in order to pass the name as an argument through the
// dialog window.
public string GalleryName {
get {
return gallery_name;
} set {
gallery_name = value;
}
}
public string GalleryPath {
get {
return gallery_path;
}
}
public string TmpPath {
get {
return tmpdir;
} set {
tmpdir = value;
}
}
public System.Threading.Thread ScalingThread {
get {
return command_thread;
}
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]