1
//This file is part of AcetoneISO. Copyright 2006,2007,2008,2009 Marco Di Antonio and Fabrizio Di Marco (acetoneiso@gmail.com)
3
// AcetoneISO is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
8
// AcetoneISO 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
11
// GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with AcetoneISO. If not, see <http://www.gnu.org/licenses/>.
18
#include <QDBusConnection>
19
#include <QDBusInterface>
20
#include <QDBusMessage>
26
#include <Phonon/MediaObject>
27
#include <Phonon/AudioOutput>
28
#include "erase_dvd.h"
31
cancellare cd completo: wodim -verbose dev=/dev/sr0 blank=all
32
cancellare cd rapido: wodim -verbose dev=/dev/sr0 blank=fast
33
dice il tipo di media inserito: hal-get-property "--key volume.disc.type --udi $udi
37
erasedvd::erasedvd( QWidget * parent, Qt::WFlags f)
43
loaded_success = false;
44
QCoreApplication::setApplicationName("AcetoneISO");
45
connect( start, SIGNAL( clicked() ), this, SLOT( start_erase() ) );
56
void erasedvd::device_scan() {
59
/*creo la connessione dbus a hal*/
60
QDBusConnection conn = QDBusConnection::systemBus();
61
QDBusInterface hal("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", conn);
62
/*cerco tutti i dispositivi storage.cdrom con hal via dbus*/
63
QDBusMessage msg = hal.call( "FindDeviceByCapability", "storage.cdrom");
65
QList<QVariant> devices = msg.arguments();
66
/*per ogni udi (dispositivo cdrom) che trovo, ricavo vendor, model, velocità e path*/
68
//disabilita tutto se non viene trovato almeno 1 periferica
69
int count = devices.count();
71
QMessageBox::warning(this, "AcetoneISO::warning", tr("No CD/DVD device found.\nIf you think this is a bug please report it."));
73
devices_combo->addItem( tr("No CD/DVD device found") );
78
QIcon icon_optical_drive( ":/images/drive-optical.png" );
80
//scannerizzo tutte le periferiche e le aggiungo nella combobox. questa funzione viene chiamato una sola volta.
81
QVariant name(devices);
85
QString cdrom = name.toStringList()[0];
86
qDebug() << "Found device: " << cdrom;
87
QDBusInterface device("org.freedesktop.Hal", cdrom, "org.freedesktop.Hal.Device", conn);
89
//vedo se effittivamente il device puo scrivere su dischi dvd-rw
90
//controllo in seguito se puo scrivere su dvd+rw dal momento che se puo scrivere su dvd+rw puo anche farlo su dvd-rw ma questo ragionamento non funziona al contrario
91
msg = device.call("GetProperty", "storage.cdrom.dvdrw");
92
QVariant vcan_write_cdrw = msg.arguments()[0];
93
bool can_write_cdrw = vcan_write_cdrw.toBool();
94
if (!can_write_cdrw) {
98
//success si ricorda sempre la posizione in cui aggiungere all'array indipendentemente dal cc del ciclo while
99
success = success + 1;
100
//aggiungo id nell'array
101
id_device.insert(success, cdrom);
102
/*ottengo il nome del vendor del cdrom*/
103
msg = device.call("GetProperty", "storage.vendor");
104
QVariant var = msg.arguments()[0];
105
QString vendor = var.toStringList()[0];
106
qDebug() << "VENDOR" << vendor;
107
/*ottengo il nome del modello del cdrom*/
108
msg = device.call("GetProperty", "storage.model");
109
QVariant var2 = msg.arguments()[0];
110
QString model = var2.toStringList()[0];
111
qDebug() << "MODEL" << model;
113
/*ottengo il path del dispositivo cdrom*/
114
msg = device.call("GetProperty", "block.device");
115
QVariant var3 = msg.arguments()[0];
116
device_path.insert(success, var3.toStringList()[0]);
117
qDebug() << "PATH" << device_path;
119
msg = device.call("GetProperty", "storage.firmware_version");
120
QVariant firmwarev = msg.arguments()[0];
121
QString firmware = firmwarev.toString();
122
/*aggiungo il nome del device nella combobox*/
123
QString final_device = vendor.append( "\t" + model + " " + firmware );
124
devices_combo->insertItem(success,icon_optical_drive, " " + final_device );
130
//if < 1 significa che sebbene ci sono 1 o piu periferiche cdrom, nessuna e' capace di scrivere su cd-rw
131
if (devices_combo->count() < 1) {
133
QMessageBox::warning(this, "AcetoneISO::warning", tr("No CD/DVD device found capable of writing to DVD-RW discs.\nIf you think this is a bug please report it."));
136
else { //c'e' almeno 1 periferica cdrom in grado di scrivere su dischi cd-rw
137
loaded_success = true;
138
//crea un timer cosi aggiorna automaticamente la label_info
139
timer = new QTimer(this);
140
connect(timer, SIGNAL(timeout()), this, SLOT(media_available()));
142
connect( devices_combo, SIGNAL(currentIndexChanged(int) ), this , SLOT( combo_changed(int) ) );
148
void erasedvd::media_available() {
149
//qDebug() << "media_available()";
150
//se sto masterizzando deve uscire da qui
152
start->setEnabled(false);
153
label_info->setText(tr("The")+ " " + discotipo + " " + tr("is getting blanked..."));
157
//if < 1 it means there are no devices capaci di scrivere su dischi cd-rw
158
if (devices_combo->count() < 1) {
162
//se non e' visibile deve disconnettere le connessioni
163
if (loaded_success) {
164
if (!devices_combo->isVisible()) {
165
disconnect(devices_combo, 0, 0, 0);
166
disconnect(timer, 0, 0, 0);
167
loaded_success = false;
170
//scopro se ho un cd dentro il device
171
/*creo la connessione dbus a hal*/
172
QDBusConnection conn = QDBusConnection::systemBus();
174
//prendo indice corrente della combobox cosi so chi l'id della periferica selezionata
175
int current_index = devices_combo->currentIndex();
176
QString id = id_device[current_index];
178
//mi connetto alla periferica corrente selezionata in combobox
179
QDBusInterface device("org.freedesktop.Hal", id, "org.freedesktop.Hal.Device", conn);
180
//vedo se e' inserito un cd
181
msg = device.call("GetProperty", "storage.removable.media_available");
182
QVariant var5 = msg.arguments()[0];
183
bool opticDev = var5.toBool();
184
QString plusminus = QString::fromUtf8("\xC2\xB1"); //0xC2 0xB1
186
label_info->setText(tr("Insert a DVD") + plusminus + "RW " + tr("disc.") );
187
start->setEnabled(false);
188
//devices_combo->setItemText(cc,tr("No Media Inserted, insert a media and click on refresh button."));
192
//vedo il tipo di cd inserito
194
QDBusInterface newh("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", conn);
195
fbp = newh.call("FindDeviceStringMatch", "info.parent", id);
196
QList<QVariant> var6 = fbp.arguments();
197
QString disc_type = var6.at(0).toString();
198
QDBusInterface device_type("org.freedesktop.Hal", disc_type, "org.freedesktop.Hal.Device", conn);
199
msg = device_type.call("GetProperty", "volume.disc.type");
200
QString var7 = msg.arguments()[0].toString();
201
QString disc_is = var7;
202
//ferma in caso che il disco inserito non sia un disco DVD±RW
203
if ( (disc_is != "dvd_rw") and (disc_is != "dvd_plus_rw") ) {
204
label_info->setText(tr("The disc isn't a DVD") + plusminus + "RW. " +tr("Please insert a DVD") + plusminus + "RW " + tr("disc."));
205
start->setEnabled(false);
209
if (disc_is == "dvd_rw") {
210
discotipo = "DVD-RW";
213
discotipo = "DVD+RW";
214
msg = device.call("GetProperty", "storage.cdrom.dvdplusrw");
215
QVariant vcan_write_cdrw = msg.arguments()[0];
216
bool discobool = vcan_write_cdrw.toBool();
218
label_info->setText( tr("You inserted a DVD+RW disc, however your CD/DVD device is uncapable of writing to DVD+RW discs.") );
219
start->setEnabled(false);
225
label_info->setText(discotipo + " " + tr("succesfully found in device."));
226
start->setEnabled(true);
230
//gestisce quando l'utente cambia periferica nella combobox
231
void erasedvd::combo_changed(int n) {
238
void erasedvd::start_erase() {
240
QString type = discotipo;
242
msgBox.setText(tr("You decided to blank the") + " " + discotipo + tr("\nAre you sure?"));
243
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
244
switch (msgBox.exec()) {
245
case QMessageBox::Yes:
250
case QMessageBox::No:
256
// should never be reached
261
if (radioButton->isChecked()) {
262
erase_type = "complete";
270
QString dev = device_path.at(devices_combo->currentIndex());
272
//dev = dev.prepend("dev=");
273
textBrowser->clear();
274
erase = new QProcess();
275
erase->setReadChannel(QProcess::StandardOutput);
276
erase->setProcessChannelMode(QProcess::MergedChannels);
277
//connection to update the display
278
connect(erase, SIGNAL(readyReadStandardOutput()), SLOT(updateEraseDisplay() ));
279
connect(erase, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(printOutErase(int, QProcess::ExitStatus)));
280
QDir bin("/usr/bin");
281
QDir::setCurrent( bin.absolutePath() );
284
if (erase_type == "fast") {
285
erase->start("dvd+rw-format",QStringList() << dev );
288
erase->start("dvd+rw-format",QStringList() << "-force" << dev );
296
//fa loutput nel display del processo wodim
297
void erasedvd::updateEraseDisplay() {
298
erase_output = erase->readAllStandardOutput();
299
//questo evita che prende un output vuoto
300
if (erase_output.size() > 2 ) {
301
eraseoutput_real = erase_output; //questo si ricorda sempre dell'ultimo output NON vuoto
302
textBrowser->setPlainText(erase_output);
305
textBrowser->setPlainText(eraseoutput_real);
310
//gestisce quando il processo dvd+rw-format finisce
311
void erasedvd::printOutErase(int, QProcess::ExitStatus) {
315
//controllo se il dvd e' gia formattato o se cmq non necessita di una formattazione secondo il sofware dvd+r-format
316
QByteArray str = "already";
317
bool contains = eraseoutput_real.contains(str); //prendo l'ultimo output non vuoto
318
eraseoutput_real = "";
320
QMessageBox::information(this, "AcetoneISO",tr("The") + " " + discotipo + " " + tr("is already formatted.\nThere is no need to format it because you can simply overwrite the media.\nIf you really want to blank it, choose Blank the Entire disc in the below window but we highly discourage you from doing so.\nOverwriting the") + " " + discotipo + " " + tr("is the simplest and safest thing to do."));
325
if (eject->isChecked()) {
326
QString dev = device_path.at(devices_combo->currentIndex());
327
EJect.start("eject",QStringList() << dev );
330
int valore_uscita = erase->exitCode();
331
if(valore_uscita == 0) {
332
if (playcheckbox->isChecked()) {
335
QMessageBox::information(this, "AcetoneISO",tr("Process Succesfully Finished!"));
336
textBrowser->clear();
339
if (playcheckbox->isChecked()) {
342
QMessageBox::critical(this, "AcetoneISO","Process Error Code: " + QString::number(valore_uscita) );
347
void erasedvd::enable_buttons() {
348
start->setEnabled(true);
349
devices_combo->setEnabled(true);
350
eject->setEnabled(true);
351
radioButton->setEnabled(true);
352
radioButton_2->setEnabled(true);
353
playcheckbox->setEnabled(true);
355
//disabilita i bottoni
356
void erasedvd::disable_buttons() {
357
start->setEnabled(false);
358
devices_combo->setEnabled(false);
359
eject->setEnabled(false);
360
radioButton->setEnabled(false);
361
radioButton_2->setEnabled(false);
362
playcheckbox->setEnabled(false);
366
void erasedvd::play_success() {
367
Phonon::MediaObject *mediaObject;
368
Phonon::AudioOutput *audioOutput;
370
mediaObject = new Phonon::MediaObject();
371
audioOutput = new Phonon::AudioOutput(Phonon::NoCategory);
372
path = Phonon::createPath(mediaObject, audioOutput);
373
QString file(":/audio/success.ogg");
374
mediaObject->setCurrentSource(Phonon::MediaSource(file));
378
void erasedvd::play_error() {
379
Phonon::MediaObject *mediaObject;
380
Phonon::AudioOutput *audioOutput;
382
mediaObject = new Phonon::MediaObject();
383
audioOutput = new Phonon::AudioOutput(Phonon::NoCategory);
384
path = Phonon::createPath(mediaObject, audioOutput);
385
QString file(":/audio/error.ogg");
386
mediaObject->setCurrentSource(Phonon::MediaSource(file));