1 /* cdrdao - write audio CD-Rs in disc-at-once mode
2 *
3 * Copyright (C) 1998-2000 Andreas Mueller <mueller@daneb.ping.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <errno.h>
21 #include <gtkmm.h>
22 #include <gnome.h>
23
24 #include "config.h"
25
26 #include "Project.h"
27 #include "util.h"
28 #include "xcdrdao.h"
29 #include "guiUpdate.h"
30 #include "gcdmaster.h"
31 #include "MessageBox.h"
32 #include "AudioCDView.h"
33 #include "TocEdit.h"
34 #include "TocEditView.h"
35 #include "RecordTocDialog.h"
36
Project(Gtk::Window * parent)37 Project::Project(Gtk::Window* parent)
38 {
39 parent_ = parent;
40 new_ = true;
41 saveFileSelector_ = 0;
42 recordTocDialog_ = 0;
43 parent_ = NULL;
44 progressbar_ = NULL;
45 progressButton_ = NULL;
46 tocEdit_ = NULL;
47 saveFileSelector_ = NULL;
48 }
49
updateWindowTitle()50 void Project::updateWindowTitle()
51 {
52 std::string s(tocEdit_->filename());
53 s += " - ";
54 s += APP_NAME;
55 if (tocEdit_->tocDirty())
56 s += " (*)";
57
58 if (parent_)
59 parent_->set_title(s);
60 }
61
saveProject()62 void Project::saveProject()
63 {
64 if (new_) {
65 saveAsProject();
66 return;
67 }
68
69 if (tocEdit_->saveToc() == 0) {
70 statusMessage(_("Project saved to \"%s\"."), tocEdit_->filename());
71 guiUpdate(UPD_TOC_DIRTY);
72
73 } else {
74 std::string s(_("Cannot save toc to \""));
75 s += tocEdit_->filename();
76 s+= "\":";
77
78 MessageBox msg(parent_, _("Save Project"), 0, s.c_str(), strerror(errno),
79 NULL);
80 msg.run();
81 }
82 }
83
saveAsProject()84 void Project::saveAsProject()
85 {
86 if (!saveFileSelector_) {
87 saveFileSelector_ =
88 new Gtk::FileChooserDialog(_("Save Project"),
89 Gtk::FILE_CHOOSER_ACTION_SAVE);
90 saveFileSelector_->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
91 saveFileSelector_->add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
92 saveFileSelector_->set_transient_for(*parent_);
93 }
94
95 saveFileSelector_->present();
96 int result = saveFileSelector_->run();
97 saveFileSelector_->hide();
98
99 if (result == Gtk::RESPONSE_OK) {
100
101 char *s = g_strdup(saveFileSelector_->get_filename().c_str());
102
103 if (s != NULL && *s != 0 && s[strlen(s) - 1] != '/') {
104
105 if (tocEdit_->saveAsToc(stripCwd(s)) == 0) {
106 statusMessage(_("Project saved to \"%s\"."), tocEdit_->filename());
107 new_ = false; // The project is now saved
108 updateWindowTitle();
109 guiUpdate(UPD_TOC_DIRTY);
110
111 } else {
112
113 std::string m(_("Cannot save toc to \""));
114 m += tocEdit_->filename();
115 m += "\":";
116 MessageBox msg(saveFileSelector_, _("Save Project"), 0, m.c_str(),
117 strerror(errno), NULL);
118 msg.run();
119 }
120 }
121
122 if (s) g_free(s);
123 }
124 }
125
projectNumber()126 int Project::projectNumber()
127 {
128 return projectNumber_;
129 }
130
tocEdit()131 TocEdit *Project::tocEdit()
132 {
133 return tocEdit_;
134 }
135
statusMessage(const char * fmt,...)136 void Project::statusMessage(const char *fmt, ...)
137 {
138 va_list args;
139 va_start(args, fmt);
140
141 char *s = g_strdup_vprintf(fmt, args);
142
143 statusbar_->push(s);
144
145 free(s);
146
147 va_end(args);
148 }
149
tocBlockedMsg(const char * op)150 void Project::tocBlockedMsg(const char *op)
151 {
152 MessageBox msg(parent_, op, 0,
153 _("Cannot perform requested operation because "
154 "project is in read-only state."), NULL);
155 msg.run();
156 }
157