File: Unpacker.cpp

package info (click to toggle)
fatrat-unpack 1.1.2-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 1,104 kB
  • ctags: 2,579
  • sloc: cpp: 18,714; makefile: 6
file content (119 lines) | stat: -rw-r--r-- 3,081 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
FatRat download manager
http://fatrat.dolezel.info

Copyright (C) 2006-2008 Lubos Dolezel <lubos a dolezel.info>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "Unpacker.h"
#include "ProgressWidget.h"
#include <fatrat/fatrat.h>
#include <QMessageBox>
#include <QFileDialog>
#include <QProcess>
#include "PipeDlg.h"

Unpacker::Unpacker(QString file)
	: m_dialog(getMainWindow()), m_bAbort(false), m_strFile(file)
{
	m_widget = new ProgressWidget;
	addStatusWidget(m_widget, false);
	m_widget->show();
	connect(m_widget->toolRestore, SIGNAL(clicked()), &m_dialog, SLOT(show()));
}

Unpacker::~Unpacker()
{
	removeStatusWidget(m_widget);
	delete m_widget;
}

void Unpacker::setProgress(int nProgress)
{
	QMetaObject::invokeMethod(m_widget->progressBar, "setValue", Q_ARG(int, nProgress));
}

void Unpacker::setToolTip(QString toolTip)
{
	m_widget->progressBar->setToolTip(toolTip);
	//QMetaObject::invokeMethod(m_widget->progressBar, "setToolTip", Q_ARG(QString, toolTip));
}

void Unpacker::runDialog(const QList<FileEntry>& files)
{
	m_dialog.load(files);
	connect(m_dialog.pushUnpack, SIGNAL(clicked()), this, SLOT(unpack()));
	connect(m_dialog.pushAbort, SIGNAL(clicked()), this, SLOT(abort()));
	connect(m_dialog.pushHide, SIGNAL(clicked()), this, SLOT(minimize()));
	connect(m_dialog.pushPipe, SIGNAL(clicked()), this, SLOT(pipe()));
	
	m_dialog.show();
}

void Unpacker::unpack()
{
	QString dest = QFileDialog::getExistingDirectory(getMainWindow(), QObject::tr("Unpack an archive"), m_strFile);
	if(dest.isEmpty())
		return;
	
	m_dialog.pushUnpack->setEnabled(false);
	m_dialog.pushAbort->setEnabled(true);
	extract(m_dialog.getStates(), dest);
}

void Unpacker::abort()
{
	if(isRunning())
		m_bAbort = true;
	else
		deleteLater();
}

void Unpacker::pipe()
{
	PipeDlg dlg(&m_dialog);
	if(dlg.exec() != QDialog::Accepted)
		return;
	
	QProcess* prs = new QProcess;
	prs->start("sh", QStringList() << "-c" << dlg.m_strCommand);
	
	if(!prs->waitForStarted(3000))
	{
		QMessageBox::critical(&m_dialog, "FatRat", tr("Failed to execute the command."));
		delete prs;
		return;
	}
	
	m_dialog.pushUnpack->setEnabled(false);
	m_dialog.pushAbort->setEnabled(true);
	
	QList<bool> files = m_dialog.getStates();
	
	connect(prs, SIGNAL(finished(int, QProcess::ExitStatus)), prs, SLOT(deleteLater()));
	this->pipe(files.indexOf(true), prs);
}

void Unpacker::minimize()
{
	m_dialog.hide();
}

void Unpacker::setFileProgress(int index, int nProgress)
{
	m_dialog.setFileProgress(index, nProgress);
}