~ubuntu-branches/ubuntu/lucid/cdrdao/lucid

« back to all changes in this revision

Viewing changes to xdao/AddFileDialog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  cdrdao - write audio CD-Rs in disc-at-once mode
 
2
 *
 
3
 *  Copyright (C) 1998-2002  Andreas Mueller <andreas@daneb.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
 
 
21
#include <stdio.h>
 
22
#include <limits.h>
 
23
#include <math.h>
 
24
#include <assert.h>
 
25
 
 
26
#include <gtkmm.h>
 
27
#include <gnome.h>
 
28
 
 
29
#include "AddFileDialog.h"
 
30
 
 
31
#include "guiUpdate.h"
 
32
#include "TocEdit.h"
 
33
#include "Sample.h"
 
34
#include "util.h"
 
35
#include "AudioCDProject.h"
 
36
#include "xcdrdao.h"
 
37
 
 
38
AddFileDialog::AddFileDialog(AudioCDProject *project)
 
39
    : Gtk::FileSelection("")
 
40
{
 
41
  active_ = 0;
 
42
  project_ = project;
 
43
 
 
44
  set_filename("*.wav");
 
45
  show_fileop_buttons();
 
46
  set_select_multiple(true);
 
47
  set_transient_for(*project);
 
48
  mode(M_APPEND_TRACK);
 
49
 
 
50
  Gtk::Button* cancel = get_cancel_button();
 
51
  cancel->set_label(Gtk::Stock::CLOSE.id);
 
52
  cancel->set_use_stock(true);
 
53
 
 
54
  Gtk::Button* ok = get_ok_button();
 
55
  ok->set_label(Gtk::Stock::ADD.id);
 
56
  ok->set_use_stock(true);
 
57
 
 
58
  ok->signal_clicked().connect(SigC::slot(*this,&AddFileDialog::applyAction));
 
59
  cancel->signal_clicked().connect(SigC::slot(*this,
 
60
                                              &AddFileDialog::closeAction));
 
61
}
 
62
 
 
63
AddFileDialog::~AddFileDialog()
 
64
{
 
65
}
 
66
 
 
67
void AddFileDialog::mode(Mode m)
 
68
{
 
69
  mode_ = m;
 
70
 
 
71
  switch (mode_) {
 
72
  case M_APPEND_TRACK:
 
73
    set_title(_("Append Track"));
 
74
    break;
 
75
  case M_APPEND_FILE:
 
76
    set_title(_("Append File"));
 
77
    break;
 
78
  case M_INSERT_FILE:
 
79
    set_title(_("Insert File"));
 
80
    break;
 
81
  }
 
82
}
 
83
 
 
84
void AddFileDialog::start()
 
85
{
 
86
  if (active_) {
 
87
    get_window()->raise();
 
88
    return;
 
89
  }
 
90
 
 
91
  active_ = true;
 
92
  set_filename("*.wav");
 
93
  show();
 
94
}
 
95
 
 
96
void AddFileDialog::stop()
 
97
{
 
98
  if (active_) {
 
99
    hide();
 
100
    active_ = false;
 
101
  }
 
102
}
 
103
 
 
104
void AddFileDialog::update(unsigned long level)
 
105
{
 
106
  if (level & UPD_EDITABLE_STATE) {
 
107
    if (project_->tocEdit()) {
 
108
      get_ok_button()->set_sensitive(project_->tocEdit()->editable());
 
109
    }
 
110
  }
 
111
}
 
112
 
 
113
bool AddFileDialog::on_delete_event(GdkEventAny*)
 
114
{
 
115
  stop();
 
116
  return 1;
 
117
}
 
118
 
 
119
void AddFileDialog::closeAction()
 
120
{
 
121
  stop();
 
122
}
 
123
 
 
124
void AddFileDialog::applyAction()
 
125
{
 
126
  if (!project_->tocEdit() ||
 
127
      !project_->tocEdit()->editable()) {
 
128
    return;
 
129
  }
 
130
 
 
131
  Glib::ArrayHandle<std::string> sfiles = get_selections();
 
132
  std::list<std::string> files;
 
133
 
 
134
  for (Glib::ArrayHandle<std::string>::const_iterator i = sfiles.begin();
 
135
       i != sfiles.end(); i++) {
 
136
 
 
137
    const char *s = stripCwd((*i).c_str());
 
138
 
 
139
    if (s && *s != 0 && s[strlen(s) - 1] != '/')
 
140
      files.push_back(s);
 
141
  }
 
142
 
 
143
  if (files.size() > 0) {
 
144
    switch (mode_) {
 
145
    case M_APPEND_TRACK:
 
146
      project_->appendTracks(files);
 
147
      break;
 
148
      
 
149
    case M_APPEND_FILE:
 
150
      project_->appendFiles(files);
 
151
      break;
 
152
 
 
153
    case M_INSERT_FILE:
 
154
      project_->insertFiles(files);
 
155
      break;
 
156
    }
 
157
    if (files.size() > 1)
 
158
      stop();
 
159
  }
 
160
 
 
161
  set_filename("*.wav");
 
162
}