source: projects/synaptic/trunk/gtk/rgpkgcdrom.cc @ 280

Revision 280, 4.2 KB checked in by yasumichi, 15 years ago (diff)

first import

Line 
1/* rgpkgcdrom.cc - make use of the apt-pkg/cdrom.h code
2 *
3 * Copyright (c) 2000, 2001 Conectiva S/A
4 *               2004 Canonical
5 *
6 * Authors: Alfredo K. Kojima <kojima@conectiva.com.br>
7 *          Michael Vogt <michael.vogt@ubuntu.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25#include "config.h"
26#ifdef HAVE_APTPKG_CDROM
27
28#include "rgmainwindow.h"
29#include "rgpkgcdrom.h"
30#include "gsynaptic.h"
31
32#include <unistd.h>
33#include <stdio.h>
34
35#include "i18n.h"
36
37class RGDiscName : public RGGladeWindow
38{
39 protected:
40
41   GtkWidget *_textEntry;
42   bool _userConfirmed;
43
44   static void onOkClicked(GtkWidget *self, void *data);
45   static void onCancelClicked(GtkWidget *self, void *data);
46
47 public:
48   RGDiscName(RGWindow *wwin, const string defaultName);
49
50   bool run(string &name);
51};
52
53
54void RGCDScanner::Update(string text, int current)
55{
56   if(text.size() > 0)
57      gtk_label_set_text(GTK_LABEL(_label), text.c_str());
58
59   if(current > 0)
60      gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(_pbar),
61                                    ((float)current) / totalSteps);
62   show();
63   RGFlushInterface();
64}
65
66bool RGCDScanner::ChangeCdrom()
67{
68   return _userDialog->proceed(_("Please insert a disc in the drive."));
69}
70
71bool RGCDScanner::AskCdromName(string &name)
72{
73   //cout << "askCdromName()" << endl;
74   RGDiscName discName(this, name);
75   
76   if (!discName.run(name)) {
77      return false;
78   }
79
80   return true;
81}
82
83RGCDScanner::RGCDScanner(RGMainWindow *main, RUserDialog *userDialog)
84: pkgCdromStatus(), RGWindow(main, "cdscanner", true, false)
85{
86   setTitle(_("Scanning CD-ROM"));
87
88   _userDialog = userDialog;
89
90   gtk_window_set_default_size(GTK_WINDOW(_win), 300, 120);
91
92   gtk_container_set_border_width(GTK_CONTAINER(_topBox), 10);
93
94   _label = gtk_label_new("\n\n");
95   gtk_widget_show(_label);
96   gtk_box_pack_start(GTK_BOX(_topBox), _label, TRUE, TRUE, 10);
97
98   _pbar = gtk_progress_bar_new();
99   gtk_widget_show(_pbar);
100   gtk_widget_set_usize(_pbar, -1, 25);
101   gtk_box_pack_start(GTK_BOX(_topBox), _pbar, FALSE, TRUE, 0);
102
103   gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_win), TRUE);
104   gtk_window_set_transient_for(GTK_WINDOW(_win), 
105                                GTK_WINDOW(main->window()));
106   gtk_window_set_position(GTK_WINDOW(_win),
107                           GTK_WIN_POS_CENTER_ON_PARENT);
108}
109
110bool RGCDScanner::run()
111{
112   pkgCdrom scanner;
113
114   return scanner.Add(this);
115}
116
117
118
119RGDiscName::RGDiscName(RGWindow *wwin, const string defaultName)
120: RGGladeWindow(wwin, "disc_name")
121{
122   setTitle(_("Disc Label"));
123   _textEntry = glade_xml_get_widget(_gladeXML, "text_entry");
124   gtk_entry_set_text(GTK_ENTRY(_textEntry), defaultName.c_str());
125
126   glade_xml_signal_connect_data(_gladeXML,
127                                 "on_ok_clicked",
128                                 G_CALLBACK(onOkClicked), this);
129   glade_xml_signal_connect_data(_gladeXML,
130                                 "on_cancel_clicked",
131                                 G_CALLBACK(onCancelClicked), this);
132   gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_win), TRUE);
133   gtk_window_set_transient_for(GTK_WINDOW(_win), 
134                                GTK_WINDOW(wwin->window()));
135   gtk_window_set_position(GTK_WINDOW(_win),
136                           GTK_WIN_POS_CENTER_ON_PARENT);
137}
138
139void RGDiscName::onOkClicked(GtkWidget *self, void *data)
140{
141   RGDiscName *me = (RGDiscName *) data;
142   me->_userConfirmed = true;
143   gtk_main_quit();
144}
145
146void RGDiscName::onCancelClicked(GtkWidget *self, void *data)
147{
148   gtk_main_quit();
149}
150
151bool RGDiscName::run(string &discName)
152{
153   _userConfirmed = false;
154   show();
155   gtk_main();
156   discName = gtk_entry_get_text(GTK_ENTRY(_textEntry));
157   return _userConfirmed;
158}
159
160#endif
161
162// vim:sts=4:sw=4
Note: See TracBrowser for help on using the repository browser.