~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/cdroms.c

  • Committer: Balint Reczey
  • Date: 2019-09-20 20:02:13 UTC
  • mfrom: (975.1.4 master)
  • Revision ID: balint.reczey@canonical.com-20190920200213-8mx0d8aitaf1xo9c
MergeĀ lp:~rbalint/update-notifier/updates-available-world-readable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifdef HAVE_CONFIG_H
 
3
#include "config.h"
 
4
#endif
 
5
#include <glib.h>
 
6
#include <glib-object.h>
 
7
#include <gtk/gtk.h>
 
8
 
 
9
#include <sys/types.h>
 
10
#include <sys/wait.h>
 
11
 
 
12
#include "update-notifier.h"
 
13
#include "cdroms.h"
 
14
 
 
15
#define CDROM_CHECKER PACKAGE_LIB_DIR"/update-notifier/apt-cdrom-check"
 
16
 
 
17
/* responses for the dialog */
 
18
enum {
 
19
   RES_START_PM=1,
 
20
   RES_DIST_UPGRADER=2,
 
21
   RES_APTONCD=3
 
22
};
 
23
 
 
24
/* Returnvalues from apt-cdrom-check:
 
25
    # 0 - no ubuntu CD
 
26
    # 1 - CD with packages
 
27
    # 2 - dist-upgrader CD
 
28
    # 3 - aptoncd media
 
29
*/
 
30
enum {
 
31
   NO_CD,
 
32
   CD_WITH_PACKAGES,
 
33
   CD_WITH_DISTUPGRADER,
 
34
   CD_WITH_APTONCD
 
35
};
 
36
 
 
37
static void
 
38
distro_cd_detected(int cdtype,
 
39
                   const char *mount_point)
 
40
{
 
41
   GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
 
42
                                              GTK_MESSAGE_QUESTION, 
 
43
                                              GTK_BUTTONS_NONE,
 
44
                                              NULL );
 
45
   gchar *title, *markup;
 
46
   switch(cdtype) {
 
47
   case CD_WITH_PACKAGES:
 
48
      title = _("Software Packages Volume Detected");
 
49
      markup = _("<span weight=\"bold\" size=\"larger\">"
 
50
            "A volume with software packages has "
 
51
            "been detected.</span>\n\n"
 
52
            "Would you like to open it with the "
 
53
            "package manager?");
 
54
      gtk_dialog_add_buttons(GTK_DIALOG(dialog), 
 
55
                             GTK_STOCK_CANCEL,
 
56
                             GTK_RESPONSE_REJECT,
 
57
                             _("Start Package Manager"), 
 
58
                             RES_START_PM,
 
59
                             NULL);
 
60
      gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_START_PM);
 
61
      break;
 
62
   case CD_WITH_DISTUPGRADER:
 
63
      title = _("Upgrade volume detected");
 
64
      markup = _("<span weight=\"bold\" size=\"larger\">"
 
65
            "A distribution volume with software packages has "
 
66
            "been detected.</span>\n\n"
 
67
            "Would you like to try to upgrade from it automatically? ");
 
68
      gtk_dialog_add_buttons(GTK_DIALOG(dialog), 
 
69
                             GTK_STOCK_CANCEL,
 
70
                             GTK_RESPONSE_REJECT,
 
71
                             _("Run upgrade"), 
 
72
                             RES_DIST_UPGRADER,
 
73
                             NULL);
 
74
      gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_DIST_UPGRADER);
 
75
      break;
 
76
#if 0  //  we don't have aptoncd support currently, g-a-i is not
 
77
       // in the archive anymore
 
78
   case CD_WITH_APTONCD:
 
79
      title = _("APTonCD volume detected");
 
80
      markup = _("<span weight=\"bold\" size=\"larger\">"
 
81
            "A volume with unofficial software packages has "
 
82
            "been detected.</span>\n\n"
 
83
            "Would you like to open it with the "
 
84
            "package manager?");
 
85
      gtk_dialog_add_buttons(GTK_DIALOG(dialog), 
 
86
                             GTK_STOCK_CANCEL,
 
87
                             GTK_RESPONSE_REJECT,
 
88
                             _("Start package manager"), 
 
89
                             RES_START_PM,
 
90
                             NULL);
 
91
      gtk_dialog_set_default_response (GTK_DIALOG(dialog), RES_START_PM);
 
92
      break;      
 
93
#endif
 
94
   default:
 
95
      g_assert_not_reached();
 
96
   }
 
97
 
 
98
   gtk_window_set_title(GTK_WINDOW(dialog), title);
 
99
   gtk_window_set_skip_taskbar_hint (GTK_WINDOW(dialog), FALSE);
 
100
   gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), markup);
 
101
 
 
102
   int res = gtk_dialog_run (GTK_DIALOG (dialog));
 
103
   switch(res) {
 
104
   gchar *argv[5];
 
105
   case RES_START_PM:
 
106
      argv[0] = "/usr/lib/update-notifier/backend_helper.py";
 
107
      argv[1] = "add_cdrom";
 
108
      argv[2] = (gchar *)mount_point;
 
109
      argv[3] = NULL;
 
110
      g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
 
111
      break;
 
112
   case RES_DIST_UPGRADER:
 
113
      argv[0] = "/usr/bin/pkexec";
 
114
      argv[1] = "/usr/lib/update-notifier/cddistupgrader";
 
115
      argv[2] = (gchar *)mount_point;
 
116
      argv[3] = NULL;
 
117
      g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL);
 
118
      break;
 
119
   default:
 
120
      /* do nothing */
 
121
      break;
 
122
   }
 
123
   gtk_widget_destroy (dialog);
 
124
}
 
125
 
 
126
int
 
127
main (int argc, char **argv)
 
128
{
 
129
    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
 
130
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 
131
    textdomain(GETTEXT_PACKAGE);
 
132
 
 
133
    if ( argc != 3 )
 
134
    {
 
135
        printf("usage: %s cdtype mountpoint", argv[0]);
 
136
        return 1;
 
137
    }
 
138
    else
 
139
    {
 
140
        int cdtype = atoi(argv[1]);
 
141
        char *mount_point = argv[2];
 
142
        if(cdtype > 0) {
 
143
            gtk_init (&argc, &argv);
 
144
            distro_cd_detected(cdtype, mount_point);
 
145
            return 0;
 
146
        }
 
147
    }
 
148
}