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
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "update-notifier.h"
#include "cdroms.h"
#define CDROM_CHECKER PACKAGE_LIB_DIR"/update-notifier/apt-cdrom-check"
/* responses for the dialog */
enum {
RES_START_PM=1,
RES_DIST_UPGRADER=2,
RES_APTONCD=3
};
/* Returnvalues from apt-cdrom-check:
# 0 - no ubuntu CD
# 1 - CD with packages
# 2 - dist-upgrader CD
# 3 - aptoncd media
*/
enum {
NO_CD,
CD_WITH_PACKAGES,
CD_WITH_DISTUPGRADER,
CD_WITH_APTONCD
};
static void
distro_cd_detected(int cdtype,
const char *mount_point)
{
GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
NULL );
gchar *title, *markup;
switch(cdtype) {
case CD_WITH_PACKAGES:
title = _("Software Packages Volume Detected");
markup = _("<span weight=\"bold\" size=\"larger\">"
"A volume with software packages has "
"been detected.</span>\n\n"
"Would you like to open it with the "
"package manager?");
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
_("Start Package Manager"),
RES_START_PM,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_START_PM);
break;
case CD_WITH_DISTUPGRADER:
title = _("Upgrade volume detected");
markup = _("<span weight=\"bold\" size=\"larger\">"
"A distribution volume with software packages has "
"been detected.</span>\n\n"
"Would you like to try to upgrade from it automatically? ");
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
_("Run upgrade"),
RES_DIST_UPGRADER,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_DIST_UPGRADER);
break;
#if 0 // we don't have aptoncd support currently, g-a-i is not
// in the archive anymore
case CD_WITH_APTONCD:
title = _("APTonCD volume detected");
markup = _("<span weight=\"bold\" size=\"larger\">"
"A volume with unofficial software packages has "
"been detected.</span>\n\n"
"Would you like to open it with the "
"package manager?");
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
_("Start package manager"),
RES_START_PM,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_START_PM);
break;
#endif
default:
g_assert_not_reached();
}
gtk_window_set_title(GTK_WINDOW(dialog), title);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW(dialog), FALSE);
gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), markup);
int res = gtk_dialog_run (GTK_DIALOG (dialog));
switch(res) {
gchar *argv[5];
case RES_START_PM:
argv[0] = "/usr/lib/update-notifier/backend_helper.py";
argv[1] = "add_cdrom";
argv[2] = (gchar *)mount_point;
argv[3] = NULL;
g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
break;
case RES_DIST_UPGRADER:
argv[0] = "/usr/bin/pkexec";
argv[1] = "/usr/lib/update-notifier/cddistupgrader";
argv[2] = (gchar *)mount_point;
argv[3] = NULL;
g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
break;
default:
/* do nothing */
break;
}
gtk_widget_destroy (dialog);
}
int
main (int argc, char **argv)
{
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
if ( argc != 3 )
{
printf("usage: %s cdtype mountpoint", argv[0]);
return 1;
}
else
{
int cdtype = atoi(argv[1]);
char *mount_point = argv[2];
if(cdtype > 0) {
gtk_init (&argc, &argv);
distro_cd_detected(cdtype, mount_point);
return 0;
}
}
}
|