1
//MountManager - the program for easy mounting of storage devices in Linux
2
//Copyright (C) 2007-2008 Tikhonov Sergey
4
//This file is part of MountManager Plugin "Images mounting"
6
//This program is free software; you can redistribute it and/or
7
//modify it under the terms of the GNU General Public License
8
//as published by the Free Software Foundation; either version 2
9
//of the License, or (at your option) any later version.
11
//This program is distributed in the hope that it will be useful,
12
//but WITHOUT ANY WARRANTY; without even the implied warranty of
13
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
//GNU General Public License for more details.
16
//You should have received a copy of the GNU General Public License
17
//along with this program; if not, write to the Free Software
18
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include <QtGui/QDialog>
20
#include <QtGui/QAction>
21
#include <QtGui/QGridLayout>
22
#include <QtGui/QPushButton>
23
#include <QtGui/QComboBox>
24
#include <QtGui/QLineEdit>
25
#include <QtGui/QLabel>
26
#include <QtGui/QCheckBox>
27
#include <QtGui/QFileDialog>
28
#include <QtCore/QDir>
29
#include <QtCore/QUrl>
31
#include <QDesktopServices>
32
#include "imagesmounting.h"
34
ImagesMounting::ImagesMounting(QWidget *parent) {
35
mainWidget = new QDialog(parent);
37
// To define open or not mount point directory after mounting
40
homePath = QDir::homePath();
41
if (!QDir(homePath + "/.mountmanager/").exists())
42
QDir().mkpath(homePath + "/.mountmanager/");
43
tempIsoImagePath = homePath + "/.mountmanager/temp_isoimage.iso";
45
process = new QProcess(this);
46
connect(process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)));
48
QAction *action = new QAction(this);
49
action->setText(tr("Images mounting"));
50
action->setIcon(QIcon(":/icons/main.png"));
51
connect(action,SIGNAL(triggered()),mainWidget,SLOT(show()));
52
actions.append(action);
54
mountButton = new QPushButton(tr("Mount"));
55
connect(mountButton,SIGNAL(clicked()),this,SLOT(mount()));
57
unmountButton = new QPushButton(tr("Unmount"));
58
connect(unmountButton,SIGNAL(clicked()),this,SLOT(unmount()));
60
closeButton = new QPushButton(tr("Close"));
61
connect(closeButton,SIGNAL(clicked()),mainWidget,SLOT(hide()));
63
imagePath = new QLineEdit;
64
mountPointPath = new QLineEdit;
65
chooseMountPointPath = new QPushButton;
66
chooseMountPointPath->setIcon(QIcon(":/icons/choose.png"));
67
connect(chooseMountPointPath,SIGNAL(clicked()),this,SLOT(chooseMountPoint()));
69
chooseImagePath = new QPushButton;
70
chooseImagePath->setIcon(QIcon(":/icons/choose.png"));
71
connect(chooseImagePath,SIGNAL(clicked()),this,SLOT(chooseImage()));
73
openDirAfterMounting = new QCheckBox(tr("Open directory after mounting"));
75
QHBoxLayout *buttonsLayout = new QHBoxLayout;
76
buttonsLayout->addStretch();
77
buttonsLayout->addWidget(mountButton);
78
buttonsLayout->addWidget(unmountButton);
79
buttonsLayout->addWidget(closeButton);
81
QGridLayout *gridLayout = new QGridLayout;
82
gridLayout->addWidget(new QLabel(tr("Choose image") + ":"),0,0);
83
gridLayout->addWidget(imagePath,0,1);
84
gridLayout->addWidget(chooseImagePath,0,2);
85
gridLayout->addWidget(new QLabel(tr("Choose mount point") + ":"),1,0);
86
gridLayout->addWidget(mountPointPath,1,1);
87
gridLayout->addWidget(chooseMountPointPath,1,2);
88
gridLayout->setColumnStretch(1,1);
90
QVBoxLayout *mainLayout = new QVBoxLayout;
91
mainLayout->addLayout(gridLayout);
92
mainLayout->addWidget(openDirAfterMounting);
93
mainLayout->addStretch();
94
mainLayout->addLayout(buttonsLayout);
95
mainWidget->setLayout(mainLayout);
96
mainWidget->setWindowTitle(tr("Images mounting"));
97
mainWidget->setWindowIcon(QIcon(":/icons/main.png"));
98
mainWidget->resize(500,mainWidget->sizeHint().height());
101
ImagesMounting::~ImagesMounting() {
103
foreach (QAction *action,actions)
106
delete unmountButton;
109
delete mountPointPath;
110
delete chooseImagePath;
111
delete chooseMountPointPath;
112
delete openDirAfterMounting;
115
void ImagesMounting::setParent(QObject *parent) {
116
connect(this,SIGNAL(showError(const QString&)),parent,SLOT(showError(const QString &)));
119
const QString ImagesMounting::pluginName() const {
120
return tr("Images mounting");
123
const QString ImagesMounting::pluginDescription() const {
124
return tr("With help of this plugin you can mount images of different formats from Nero to Iso");
127
QDialog* ImagesMounting::dialog() const {
131
QDockWidget* ImagesMounting::dockWidget() const {
135
QMenu* ImagesMounting::menu() const {
139
QToolBar* ImagesMounting::toolBar() const {
143
Actions ImagesMounting::menuActions() const {
147
void ImagesMounting::chooseImage() {
148
QString path = QFileDialog::getOpenFileName(mainWidget,tr("Choose image"),homePath,tr("Images formats (*.iso *.nrg *.bin *.mdf *.ccd *.img *.sub *.b5i *.cdi *.pdi *.dmg)"));
151
imageType = QFileInfo(path).fileName().split(".").last();
152
imagePath->setText(path);
155
void ImagesMounting::chooseMountPoint() {
156
QString path = QFileDialog::getExistingDirectory(mainWidget,tr("Choose mount point"),"/mnt");
159
mountPointPath->setText(path);
162
void ImagesMounting::mount() {
163
if (imagePath->text().isEmpty()) {
164
imagePath->setFocus();
167
if (mountPointPath->text().isEmpty()) {
168
mountPointPath->setFocus();
171
if (imageType != "iso" && convert()) {
173
process->start(QString("mount -t iso9660 -o loop \"%1\" \"%2\"").arg(tempIsoImagePath).arg(mountPointPath->text()));
175
else if (imageType == "iso") {
176
process->start(QString("mount -t iso9660 -o loop \"%1\" \"%2\"").arg(imagePath->text()).arg(mountPointPath->text()));
181
bool ImagesMounting::convert() {
182
process->waitForFinished();
184
// Define the program for converting to iso
185
if (imageType.isEmpty() && QFileInfo(imagePath->text()).fileName().split(".").count() > 1)
186
imageType = QFileInfo(imagePath->text()).fileName().split(".").last();
187
if (imageType.isEmpty()) {
188
emit(showError(tr("[%1] File name is invalid.").arg(pluginName())));
191
if (imageType == "nrg")
193
else if (imageType == "bin" || imageType == "cue")
195
else if (imageType == "mdf")
197
else if (imageType == "img" || imageType == "ccd" || imageType == "sub")
199
else if (imageType == "b5i")
201
else if (imageType == "cdi")
203
else if (imageType == "pdi")
205
else if (imageType == "dmg")
207
if (program.isEmpty())
209
process->start(QString("%1 \"%2\" \"%3\"").arg(program).arg(imagePath->text()).arg(tempIsoImagePath));
210
if (process->readAllStandardError().isEmpty())
212
emit(showError(tr("[%1] Cannot to convert your image to iso image. Maybe image is corrupted").arg(pluginName())));
216
void ImagesMounting::processFinished(int exitCode,QProcess::ExitStatus) {
218
emit(showError(tr("[%1] We are sorry, but was error").arg(pluginName()) + ": " + QString::fromUtf8(process->readAllStandardError().data())));
219
else if (wasMounting && openDirAfterMounting->isChecked())
220
QDesktopServices::openUrl(QUrl(mountPointPath->text()));
221
if (exitCode == 0 && wasMounting) {
223
mountPointPath->clear();
228
void ImagesMounting::unmount() {
229
QString path = QFileDialog::getExistingDirectory(mainWidget,tr("Choose mount point"),"/mnt");
232
process->start(QString("umount %1").arg(path));
235
Q_EXPORT_PLUGIN2(imagesmounting,ImagesMounting)