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

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

first import

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