1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#!/usr/bin/perl
################################################################################
# MandrakeOnline #
# #
# Copyright (C) 2003-2004 MandrakeSoft #
# #
# Daouda Lo <daouda@mandrakesoft.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License Version 2 as #
# published by the Free Software Foundation. #
# #
# 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. #
################################################################################
use strict;
use lib qw(/usr/lib/libDrakX);
use common;
use Gtk2::TrayIcon;
eval { require ugtk2; ugtk2->import(qw(:all)); require Gtk2::Pango; };
if ($@) {
print "This program cannot be run in console mode.\n";
c::_exit(0); #- skip ugtk2::END
}
my ($eventbox, $img);
add_icon_path("/usr/share/mdkonline/pixmaps/");
my $menu;
my $nowindow = 1;
my %state = (
okay => {
colour => [ 'green' ],
changes => [ 'busy', 'critical', 'disconnected' ],
menu => [ 'update', 'configureApplet', 'check', 'weblink' ],
},
critical => {
colour => [ 'orange' ],
changes => [ 'okay', 'busy', 'critical', 'disconnected' ],
menu => [ 'update', 'configureApplet', 'check', 'weblink' ],
},
busy => {
colour => [ 'orange' ],
changes => [ 'okay', 'critical', 'error', 'disconnected' ],
menu => [ ],
},
error => {
colour => [ 'red' ],
changes => [ 'okay' ],
menu => [ 'update', 'check' ],
},
noconfig => {
colour => [ 'orange' ],
changes => [ 'okay' ],
menu => [ 'update', 'weblink', 'register' ],
},
disconnected => {
colour => [ 'orange' ],
changes => [ 'okay', 'busy', 'critical', 'error' ],
menu => [ 'confNetwork' ],
}
);
my %actions = (
'update' => { name => N("Launch Mandrake Update"), launch => sub { launchUpdate() } },
'configureApplet' => { name => N("Configuration"), launch => sub { configure() } },
'check' => { name => N("Check Updates"), launch => sub { checkUpdates() } },
'weblink' => { name => N("Online WebSite"), launch => sub { getsite() } },
'confNetwork' => { name => N("Configure Network"), sub { configNetwork() } },
'register' => { name => N("Register Now!"), sub { register() } }
);
gtkadd(my $icon = Gtk2::TrayIcon->new("MdkApplet"),
gtkpack_( Gtk2::VBox->new(0, 3),
0, gtkadd($eventbox = Gtk2::EventBox->new,
gtkpack($img = Gtk2::Image->new)
)
)
);
print "Setting okay ...\n";
$menu = setState('okay');
$eventbox->signal_connect(button_press_event => sub {
$_[1]->button == 1 and showMainWindow(); #just for testing
$_[1]->button == 3 && $menu and $menu->popup(undef, undef, undef, undef, $_[1]->button, $_[1]->time);
});
$icon->show_all;
Gtk2->main;
ugtk2::exit(0);
sub showMainWindow() {
my $w = Gtk2::Window->new('toplevel');
$w->set_title(N("Mandrake Updates Applet"));
$w->signal_connect(delete_event => sub { $w->destroy });
$w->set_position('center');
my ($choice, $isAvailable, $isNetwork, $time);
$time = `date`; chomp($time);
my $autocheck;
gtkadd($w,
gtkpack__(Gtk2::VBox->new(0,5),
gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Actions")), 'etched_in'),
gtkpack_(Gtk2::VBox->new(0, 3),
1, gtksignal_connect(Gtk2::Button->new(N("Check Updates")), clicked => sub { checkUpdates() }),
1, gtksignal_connect(Gtk2::Button->new(N("Start MandrakeUpdate")), clicked => sub { mdkUpdate() }),
1, gtksignal_connect(Gtk2::Button->new(N("Configure")), clicked => sub { launchMdkOnline() }),
1, gtksignal_connect(Gtk2::Button->new(N("See logs")), clicked => sub { displayLogs() }),
)
),
gtkadd(gtkset_shadow_type(Gtk2::Frame->new(N("Status")), 'etched_in'),
gtkpack_(Gtk2::VBox->new(0, 3),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("Network Connection: ")),
0, Gtk2::Label->new($isNetwork ? N("Up") : N("Down"))
),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("New Updates: ")),
0, Gtk2::Label->new($isAvailable ? N("Available") : N("Not Available"))
),
0, gtkpack_(Gtk2::HBox->new(0, 3),
0, Gtk2::Label->new(N("Last check: ")),
0, Gtk2::Label->new($time)
),
)
),
gtkpack(Gtk2::HSeparator->new),
gtkpack(gtksignal_connect(Gtk2::Button->new(N("Close")), clicked => sub {
$w->destroy;
})
)
));
$w->show_all
}
sub displayLogs() {
}
sub confNetwork {
system("/usr/sbin/net_monitor" . "&")
}
sub launchUpdate {
system("/usr/sbin/MandrakeUpdate" . "&");
}
sub CheckUpdates {
}
sub register {
system("/usr/sbin/mdkonline" . "&")
}
sub getsite {
my $b = browser();
system("$b " . "https://www.mandrakeonline.com" . "&")
}
sub browser {
require any;
my $wm = any::running_window_manager();
member ($wm, 'kwin', 'gnome-seession') or $wm = 'other';
my %Br = (
'kwin' => 'konqueror',
'gnome-session' => 'mozilla',
'other' => $ENV{BROWSER} || find { -x "/usr/bin/$_"} qw(mozilla konqueror galeon)
);
$Br{$wm}
}
sub setState {
my $state_type = shift;
my $arr = $state{$state_type}{menu};
my $tmp = gtkcreate_pixbuf($state{$state_type}{colour}->[0]);
$img->set_from_pixbuf($tmp);
my $menu = Gtk2::Menu->new;
foreach (@$arr) {
my $l = $actions{$_}{name};
print "***** $_ = $l ****\n";
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label($actions{$_}{name})), activate => $actions{$_}{launch}));
}
$menu->append(gtkshow(Gtk2::SeparatorMenuItem->new));
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("About.."))), activate => sub { about() }));
$menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Quit"))), activate => sub { Gtk2->main_quit }));
$menu
}
sub about {
create_dialog(N("About Online Applet"),
#-PO Do not alter the <span ..> and </span> tags
"\t" . N("<span foreground=\"#21449C\"><u><b>Mandrake Update Notification Applet</b></u></span>\n\n<u>Version</u>: %s \n\n<u>Team</u>: Mandrake Online Team <mot\@mandrakeonline.net>\n\n<span foreground=\"#006666\"><i>This Software is under GPL</i></span>", ' 10.0 ') , { use_markup => 1 });
}
|