summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/URLQueue/MainController.pm171
-rw-r--r--lib/URLQueue/main.glade85
2 files changed, 256 insertions, 0 deletions
diff --git a/lib/URLQueue/MainController.pm b/lib/URLQueue/MainController.pm
new file mode 100644
index 0000000..b9a8dd5
--- /dev/null
+++ b/lib/URLQueue/MainController.pm
@@ -0,0 +1,171 @@
+package URLQueue::MainController;
+use strict;
+use warnings;
+use base 'Gtk2::GladeXML::Simple';
+use Path::Class;
+use URI::Find;
+use URI::Title;
+use Email::Send;
+use POSIX 'strftime';
+
+sub new {
+ my ($class,%params)=@_;
+
+ my $glade_file=file(__FILE__)->parent->file('main.glade');
+ my $self=$class->SUPER::new($glade_file);
+
+ my $target_list=Gtk2::TargetList->new();
+ $target_list->add_uri_targets(1);
+ $target_list->add_text_targets(2);
+ $self->{input}->drag_dest_set('all',
+ [qw(default copy move link private ask)],
+ []);
+ $self->{input}->drag_dest_set_target_list($target_list);
+
+ $self->{glade_dir}=$params{glade_dir};
+
+ return $self;
+}
+
+sub drag_motion {
+ my ($self, $widget, $context, $x, $y, $time) = @_;
+
+ $context->status($context->suggested_action,$time);
+
+ return 1;
+}
+
+sub drag_drop {
+ my ($self, $widget, $context, $x, $y, $time) = @_;
+
+ if (my $atom=$context->targets) {
+ $widget->drag_get_data($context, $atom, $time);
+ return 1;
+ }
+
+ return 0;
+}
+
+sub drag_data_received {
+ my ($self, $widget, $context, $x, $y, $data, $info, $time) = @_;
+
+ if ($info==1) {
+ $self->handle_uris($data->get_uris)
+ }
+ elsif ($info==2) {
+ $self->handle_text($data->get_text);
+ }
+ else {
+ warn "What is $info??";
+ }
+}
+
+sub paste_clipboard {
+ my ($self,$widget)=@_;
+
+ my $clipboard=Gtk2::Clipboard->get();
+ $clipboard->request_text(sub{$self->handle_text($_[1])});
+}
+
+sub button_release {
+ my ($self,$widget,$event)=@_;
+
+ if ($event->button==2) {
+ my $clipboard=Gtk2::Clipboard->get(Gtk2::Gdk->SELECTION_PRIMARY);
+ $clipboard->request_text(sub{$self->handle_text($_[1])});
+ }
+}
+
+sub quit {
+ Gtk2->main_quit;
+}
+
+sub handle_text {
+ my ($self,$text)=@_;
+
+ return unless $text;
+
+ # stupid hack to avoid double-drop from Firefox
+ return if ($self->{_last_text} and
+ $self->{_last_text} eq $text);
+ $self->{_last_text}=$text;
+
+ $self->{status}->push(4,'Finding uris');
+
+ {
+ my @uris;
+ my $tmptext=$text;
+ URI::Find->new(sub {
+ push @uris,$_[0]->as_string;
+ return ''
+ })->find(\$tmptext);
+
+ if ($tmptext=~/\A \s* \z/smx) {
+ $self->{status}->pop(4);
+ return $self->handle_uris(@uris);
+ }
+ }
+
+ $self->{status}->pop(4);
+
+ my ($title)=($text =~ m{ \A ^ (.*?) $}smx);
+
+ for ($title,$text) {
+ s{\A \s+}{}smx;
+ s{\s+ \z}{}smx;
+ }
+
+ $self->send_email($title,$text);
+}
+
+sub handle_uris {
+ my ($self,@uris)=@_;
+
+ @uris=grep {$_} @uris;
+
+ return unless @uris;
+
+ $self->{status}->push(5,'Titling '.(scalar @uris).' uris');
+
+ my @titles=map {URI::Title::title($_)} @uris;
+
+ $self->{status}->pop(5);
+
+ my $title=join ' - ',@titles;
+ my $body='';
+ while (@uris) {
+ my $uri=shift @uris;
+ my $name=shift @titles;
+ $body.="$title $uri\n";
+ }
+
+ $self->send_email($title,$body);
+}
+
+sub send_email {
+ my ($self,$title,$body)=@_;
+
+ my $date=strftime('%a, %d %b %Y %H:%M:%S %z',localtime(time));
+
+ my $message=<<"EOM";
+From: urlqueue\@thenautilus.net
+To: dakkar\@thenautilus.net
+Subject: $title
+Date: $date
+
+$body
+EOM
+
+ $self->{status}->push(6,'Sending the message');
+
+ my $sender=Email::Send->new({mailer=>'SMTP'});
+ $sender->mailer_args([Host=>'exelion']);
+ $sender->send($message);
+
+ $self->{status}->pop(6);
+}
+
+1;
+
+__END__
+Date: Sat, 2 Jun 2007 09:48:26 +0200
diff --git a/lib/URLQueue/main.glade b/lib/URLQueue/main.glade
new file mode 100644
index 0000000..616d274
--- /dev/null
+++ b/lib/URLQueue/main.glade
@@ -0,0 +1,85 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkWindow" id="main">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">URLQueue</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">False</property>
+ <property name="skip_taskbar_hint">False</property>
+ <property name="skip_pager_hint">False</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_UTILITY</property>
+ <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+ <property name="focus_on_map">True</property>
+ <property name="urgency_hint">False</property>
+ <signal name="destroy" handler="quit" last_modification_time="Mon, 04 Jun 2007 17:51:09 GMT"/>
+
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTextView" id="input">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ <property name="overwrite">False</property>
+ <property name="accepts_tab">False</property>
+ <property name="justification">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap_mode">GTK_WRAP_NONE</property>
+ <property name="cursor_visible">False</property>
+ <property name="pixels_above_lines">0</property>
+ <property name="pixels_below_lines">0</property>
+ <property name="pixels_inside_wrap">0</property>
+ <property name="left_margin">0</property>
+ <property name="right_margin">0</property>
+ <property name="indent">0</property>
+ <property name="text" translatable="yes"></property>
+ <signal name="drag_data_received" handler="drag_data_received" last_modification_time="Mon, 04 Jun 2007 17:51:18 GMT"/>
+ <signal name="drag_motion" handler="drag_motion" last_modification_time="Mon, 04 Jun 2007 17:57:55 GMT"/>
+ <signal name="drag_drop" handler="drag_drop" last_modification_time="Mon, 04 Jun 2007 17:58:09 GMT"/>
+ <signal name="paste_clipboard" handler="paste_clipboard" last_modification_time="Mon, 04 Jun 2007 18:14:43 GMT"/>
+ <signal name="button_release_event" handler="button_release" last_modification_time="Mon, 04 Jun 2007 18:16:41 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkStatusbar" id="status">
+ <property name="visible">True</property>
+ <property name="has_resize_grip">False</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+</glade-interface>