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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* ark -- archiver for the KDE project
*
* Copyright (C)
*
* 2005: Henrique Pinto <henrique.pinto@kdemail.net>
* 2002: Helio Chissini de Castro <helio@conectiva.com.br>
* 2001: Roberto Selbach Teixeira <maragato@conectiva.com.br>
* 2001: Corel Corporation (author: Michael Jarrett, michaelj@corel.com)
* 1999-2000: Corel Corporation (author: Emily Ezust emilye@corel.com)
* 1999: Francois-Xavier Duranceau duranceau@kde.org
* 1997-1999: Rob Palmbos palm9744@kettering.edu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 "extractiondialog.h"
#include <qvbox.h>
#include <qhbox.h>
#include <qhbuttongroup.h>
#include <qlabel.h>
#include <qradiobutton.h>
#include <qlayout.h>
#include <klocale.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kurlrequester.h>
#include <kurlcompletion.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <kcombobox.h>
#include <klineedit.h>
#include <kurlpixmapprovider.h>
#include <kdebug.h>
#include "arkutils.h"
#include "settings.h"
ExtractionDialog::ExtractionDialog( QWidget *parent, const char *name,
bool enableSelected,
const KURL& defaultExtractionDir,
const QString &prefix,
const QString &archiveName )
: KDialogBase( parent, name, true, i18n( "Extract" ), Ok | Cancel, Ok ),
m_selectedButton( 0 ), m_allButton( 0 ),
m_selectedOnly( enableSelected ), m_extractionDirectory( defaultExtractionDir ),
m_defaultExtractionDir( defaultExtractionDir.prettyURL() ), m_prefix( prefix )
{
if ( !archiveName.isNull() )
{
setCaption( i18n( "Extract Files From %1" ).arg( archiveName ) );
}
QVBox *vbox = makeVBoxMainWidget();
QHBox *header = new QHBox( vbox );
header->layout()->setSpacing( 10 );
QLabel *icon = new QLabel( header );
icon->setPixmap( DesktopIcon( "ark_extract" ) );
icon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
if ( enableSelected )
{
QVBox *whichFiles = new QVBox( header );
whichFiles->layout()->setSpacing( 6 );
new QLabel( QString( "<qt><b><font size=\"+1\">%1</font></b></qt>" )
.arg( i18n( "Extract:" ) ), whichFiles );
QHButtonGroup *filesGroup = new QHButtonGroup( whichFiles );
m_selectedButton = new QRadioButton( i18n( "Selected files only" ), filesGroup );
m_allButton = new QRadioButton( i18n( "All files" ), filesGroup );
m_selectedButton->setChecked( true );
}
else
{
new QLabel( QString( "<qt><b><font size=\"+2\">%1</font></b></qt>" )
.arg( i18n( "Extract all files" ) ), header );
}
QHBox *destDirBox = new QHBox( vbox );
QLabel *destFolderLabel = new QLabel( i18n( "Destination folder: " ), destDirBox );
destFolderLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
KHistoryCombo *combobox = new KHistoryCombo( true, destDirBox );
combobox->setPixmapProvider( new KURLPixmapProvider );
combobox->setHistoryItems( ArkSettings::extractionHistory() );
destFolderLabel->setBuddy( combobox );
KURLCompletion *comp = new KURLCompletion();
comp->setReplaceHome( true );
comp->setCompletionMode( KGlobalSettings::CompletionAuto );
combobox->setCompletionObject( comp );
combobox->setMaxCount( 20 );
combobox->setInsertionPolicy( QComboBox::AtTop );
m_urlRequester = new KURLRequester( combobox, destDirBox );
m_urlRequester->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
m_urlRequester->setMode( KFile::Directory );
if (!defaultExtractionDir.prettyURL().isEmpty() )
{
m_urlRequester->setKURL( defaultExtractionDir.prettyURL() + prefix );
}
m_viewFolderAfterExtraction = new QCheckBox( i18n( "Open destination folder after extraction" ), vbox );
m_viewFolderAfterExtraction->setChecked( ArkSettings::openDestinationFolder() );
connect( combobox, SIGNAL( returnPressed( const QString& ) ), combobox, SLOT( addToHistory( const QString& ) ) );
connect( combobox->lineEdit(), SIGNAL( textChanged( const QString& ) ),
this, SLOT( extractDirChanged( const QString & ) ) );
}
ExtractionDialog::~ExtractionDialog()
{
ArkSettings::setExtractionHistory( ( static_cast<KHistoryCombo*>( m_urlRequester->comboBox() ) )->historyItems() );
}
void ExtractionDialog::accept()
{
KURLCompletion uc;
uc.setReplaceHome( true );
KURL p( uc.replacedPath( m_urlRequester->comboBox()->currentText() ) );
//if p isn't local KIO and friends will complain later on
if ( p.isLocalFile() )
{
QFileInfo fi( p.path() );
if ( !fi.isDir() && !fi.exists() )
{
QString ltext = i18n( "Create folder %1?").arg(p.path());
int createDir = KMessageBox::questionYesNo( this, ltext, i18n( "Missing Folder" ) , i18n("Create Folder"), i18n("Do Not Create"));
if( createDir == 4 )
{
return;
}
// create directory using filename, make sure it has trailing slash
p.adjustPath(1);
if( !KStandardDirs::makeDir( p.path() ) )
{
KMessageBox::error( this, i18n( "The folder could not be created. Please check permissions." ) );
return;
}
}
if ( !ArkUtils::haveDirPermissions( p.path() ) )
{
KMessageBox::error( this, i18n( "You do not have write permission to this folder. Please provide another folder." ) );
return;
}
}
m_extractionDirectory = p;
m_selectedOnly = m_selectedButton == 0? false : m_selectedButton->isChecked();
// Determine what exactly should be added to the extraction combo list
QString historyURL = p.prettyURL();
if ( historyURL == KURL( m_defaultExtractionDir + m_prefix ).prettyURL() )
{
historyURL = m_defaultExtractionDir;
}
KHistoryCombo *combo = static_cast<KHistoryCombo*>( m_urlRequester->comboBox() );
// If the item was already in the list, delete it from the list and readd it at the top
combo->removeFromHistory( historyURL );
combo->addToHistory( historyURL );
ArkSettings::setOpenDestinationFolder( m_viewFolderAfterExtraction->isChecked() );
KDialogBase::accept();
}
void ExtractionDialog::extractDirChanged(const QString &text )
{
enableButtonOK(!text.isEmpty());
}
#include "extractiondialog.moc"
// kate: space-indent off; tab-width 4;
|