C0 code coverage information
Generated on Tue Oct 16 11:40:50 -0400 2007 with rcov 0.8.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Copyright (C) 2004-2006 Laurent Sansonetti
2 #
3 # Alexandria is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 2 of the
6 # License, or (at your option) any later version.
7 #
8 # Alexandria is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public
14 # License along with Alexandria; see the file COPYING. If not,
15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 # Boston, MA 02111-1307, USA.
17
18 module Alexandria
19 module UI
20 class ConfirmEraseDialog < AlertDialog
21 include GetText
22 GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
23
24 def initialize(parent, filename)
25 super(parent, _("File already exists"),
26 Gtk::Stock::DIALOG_QUESTION,
27 [[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
28 [_("_Replace"), Gtk::Dialog::RESPONSE_OK]],
29 _("A file named '%s' already exists. Do you want " +
30 "to replace it with the one you are generating?") \
31 % filename)
32 self.default_response = Gtk::Dialog::RESPONSE_CANCEL
33 show_all and @response = run
34 destroy
35 end
36
37 def erase?
38 @response == Gtk::Dialog::RESPONSE_OK
39 end
40 end
41
42 class ExportDialog < Gtk::FileChooserDialog
43 include GetText
44 extend GetText
45 GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
46
47 FORMATS = Alexandria::ExportFormat.all
48 THEMES = Alexandria::WebTheme.all
49
50 def initialize(parent, library)
51 backend = `uname`.chomp == "FreeBSD" ? "neant" : "gnome-vfs"
52 super(_("Export '%s'") % library.name,
53 nil,
54 Gtk::FileChooser::ACTION_SAVE,
55 backend,
56 [Gtk::Stock::HELP, Gtk::Dialog::RESPONSE_HELP],
57 [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
58 [_("_Export"), Gtk::Dialog::RESPONSE_ACCEPT])
59
60 self.transient_for = parent
61 self.current_name = library.name
62 self.signal_connect('destroy') { hide }
63
64 @parent, @library = parent, library
65
66 preview_image = Gtk::Image.new
67
68 theme_combo = Gtk::ComboBox.new
69 THEMES.each do |theme|
70 theme_combo.append_text(theme.name)
71 end
72 theme_combo.signal_connect('changed') do
73 file = THEMES[theme_combo.active].preview_file
74 preview_image.pixbuf = Gdk::Pixbuf.new(file)
75 end
76 theme_combo.active = 0
77 theme_label = Gtk::Label.new(_("_Theme:"), true)
78 theme_label.xalign = 0
79 theme_label.mnemonic_widget = theme_combo
80
81 types_combo = Gtk::ComboBox.new
82 FORMATS.each do |format|
83 text = format.name + " ("
84 if format.ext
85 text += "*." + format.ext
86 else
87 text += _("directory")
88 end
89 text += ")"
90 types_combo.append_text(text)
91 end
92 types_combo.active = 0
93 types_combo.signal_connect('changed') do
94 theme_label.visible = theme_combo.visible =
95 preview_image.visible =
96 FORMATS[types_combo.active].needs_preview?
97 end
98 types_combo.show
99
100 types_label = Gtk::Label.new(_("Export for_mat:"), true)
101 types_label.xalign = 0
102 types_label.mnemonic_widget = types_combo
103 types_label.show
104
105 # Ugly hack to add more rows in the internal Gtk::Table of the
106 # widget, which is needed because we want the export type to be
107 # aligned against the other widgets, and #extra_widget doesn't do
108 # that...
109 internal_table =
110 children[0].children[0].children[0].children[0].children[0]
111 internal_table.resize(4, 3)
112 internal_table.attach(types_label, 0, 1, 2, 3)
113 internal_table.attach(types_combo, 1, 2, 2, 3)
114 internal_table.attach(theme_label, 0, 1, 3, 4)
115 internal_table.attach(theme_combo, 1, 2, 3, 4)
116 internal_table.attach(preview_image, 2, 3, 0, 4)
117
118 while (response = run) != Gtk::Dialog::RESPONSE_CANCEL and
119 response != Gtk::Dialog::RESPONSE_DELETE_EVENT
120
121 if response == Gtk::Dialog::RESPONSE_HELP
122 begin
123 Gnome::Help.display('alexandria', 'exporting')
124 rescue => e
125 ErrorDialog.new(self, e.message)
126 end
127 else
128 begin
129 break if on_export(FORMATS[types_combo.active],
130 THEMES[theme_combo.active])
131 rescue => e
132 ErrorDialog.new(self, _("Export failed"), e.message)
133 end
134 end
135 end
136 destroy
137 end
138
139 #######
140 private
141 #######
142
143 def on_export(format, theme)
144 unless @library.respond_to?(format.message)
145 raise NotImplementedError
146 end
147 filename = self.filename
148 if format.ext
149 filename += "." + format.ext if File.extname(filename).empty?
150 if File.exists?(filename)
151 dialog = ConfirmEraseDialog.new(@parent, filename)
152 return unless dialog.erase?
153 FileUtils.rm(filename)
154 end
155 args = []
156 else
157 if File.exists?(filename)
158 unless File.directory?(filename)
159 msg = _("The target, named '%s', is a regular " +
160 "file. A directory is needed for this " +
161 "operation. Please select a directory and " +
162 "try again.") % filename
163 ErrorDialog.new(@parent, _("Not a directory"), msg)
164 return
165 end
166 else
167 Dir.mkdir(filename)
168 end
169 args = [theme]
170 end
171 format.invoke(@library, filename, *args)
172 return true
173 end
174 end
175 end
176 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.