KIO
renamedialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Stephan Kulow <coolo@kde.org> 00003 1999 - 2008 David Faure <faure@kde.org> 00004 2001, 2006 Holger Freyther <freyther@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "kio/renamedialog.h" 00023 #include <stdio.h> 00024 #include <assert.h> 00025 00026 #include <QtCore/QDate> 00027 #include <QtCore/QFileInfo> 00028 #include <QtGui/QCheckBox> 00029 #include <QtGui/QLabel> 00030 #include <QtGui/QLayout> 00031 #include <QtGui/QPixmap> 00032 #include <QtGui/QScrollArea> 00033 #include <QtGui/QScrollBar> 00034 #include <QtGui/QApplication> 00035 #include <QtGui/QDesktopWidget> 00036 #include <QtCore/QDir> 00037 00038 #include <klineedit.h> 00039 #include <kmessagebox.h> 00040 #include <kpushbutton.h> 00041 #include <kio/global.h> 00042 #include <kio/udsentry.h> 00043 #include <kdialog.h> 00044 #include <klocale.h> 00045 #include <kglobal.h> 00046 #include <kdebug.h> 00047 #include <kurl.h> 00048 #include <kfileitem.h> 00049 #include <kmimetype.h> 00050 #include <kseparator.h> 00051 #include <kstringhandler.h> 00052 #include <kstandardguiitem.h> 00053 #include <kguiitem.h> 00054 #include <ksqueezedtextlabel.h> 00055 #include <kfilemetadatawidget.h> 00056 #include <previewjob.h> 00057 00058 using namespace KIO; 00059 00061 class RenameDialog::RenameDialogPrivate 00062 { 00063 public: 00064 RenameDialogPrivate() { 00065 bCancel = 0; 00066 bRename = bSkip = bOverwrite = 0; 00067 bResume = bSuggestNewName = 0; 00068 bApplyAll = 0; 00069 m_pLineEdit = 0; 00070 m_srcPendingPreview = false; 00071 m_destPendingPreview = false; 00072 m_srcPreview = 0; 00073 m_destPreview = 0; 00074 } 00075 00076 void setRenameBoxText(const QString& fileName) { 00077 // sets the text in file name line edit box, selecting the filename (but not the extension if there is one). 00078 const QString extension = KMimeType::extractKnownExtension(fileName); 00079 m_pLineEdit->setText(fileName); 00080 00081 if (!extension.isEmpty()) { 00082 const int selectionLength = fileName.length() - extension.length() - 1; 00083 m_pLineEdit->setSelection(0, selectionLength); 00084 } else { 00085 m_pLineEdit->selectAll(); 00086 } 00087 } 00088 00089 KPushButton *bCancel; 00090 QPushButton *bRename; 00091 QPushButton *bSkip; 00092 QPushButton *bOverwrite; 00093 QPushButton *bResume; 00094 QPushButton *bSuggestNewName; 00095 QCheckBox *bApplyAll; 00096 KLineEdit* m_pLineEdit; 00097 KUrl src; 00098 KUrl dest; 00099 bool m_srcPendingPreview; 00100 bool m_destPendingPreview; 00101 QLabel* m_srcPreview; 00102 QLabel* m_destPreview; 00103 QScrollArea* m_srcArea; 00104 QScrollArea* m_destArea; 00105 KFileItem srcItem; 00106 KFileItem destItem; 00107 }; 00108 00109 RenameDialog::RenameDialog(QWidget *parent, const QString & _caption, 00110 const KUrl &_src, const KUrl &_dest, 00111 RenameDialog_Mode _mode, 00112 KIO::filesize_t sizeSrc, 00113 KIO::filesize_t sizeDest, 00114 time_t ctimeSrc, 00115 time_t ctimeDest, 00116 time_t mtimeSrc, 00117 time_t mtimeDest) 00118 : QDialog(parent), d(new RenameDialogPrivate) 00119 { 00120 setObjectName("KIO::RenameDialog"); 00121 00122 d->src = _src; 00123 d->dest = _dest; 00124 00125 setWindowTitle(_caption); 00126 00127 d->bCancel = new KPushButton(KStandardGuiItem::cancel(), this); 00128 connect(d->bCancel, SIGNAL(clicked()), this, SLOT(cancelPressed())); 00129 00130 if (_mode & M_MULTI) { 00131 d->bApplyAll = new QCheckBox(i18n("Appl&y to All"), this); 00132 d->bApplyAll->setToolTip((_mode & M_ISDIR) ? i18n("When this is checked the button pressed will be applied to all subsequent folder conflicts for the remainder of the current job.\nUnless you press Skip you will still be prompted in case of a conflict with an existing file in the directory.") 00133 : i18n("When this is checked the button pressed will be applied to all subsequent conflicts for the remainder of the current job.")); 00134 connect(d->bApplyAll, SIGNAL(clicked()), this, SLOT(applyAllPressed())); 00135 } 00136 00137 if (!(_mode & M_NORENAME)) { 00138 d->bRename = new QPushButton(i18n("&Rename"), this); 00139 d->bRename->setEnabled(false); 00140 d->bSuggestNewName = new QPushButton(i18n("Suggest New &Name"), this); 00141 connect(d->bSuggestNewName, SIGNAL(clicked()), this, SLOT(suggestNewNamePressed())); 00142 connect(d->bRename, SIGNAL(clicked()), this, SLOT(renamePressed())); 00143 } 00144 00145 if ((_mode & M_MULTI) && (_mode & M_SKIP)) { 00146 d->bSkip = new QPushButton(i18n("&Skip"), this); 00147 d->bSkip->setToolTip((_mode & M_ISDIR) ? i18n("Do not copy or move this folder, skip to the next item instead") 00148 : i18n("Do not copy or move this file, skip to the next item instead")); 00149 connect(d->bSkip, SIGNAL(clicked()), this, SLOT(skipPressed())); 00150 } 00151 00152 if (_mode & M_OVERWRITE) { 00153 const QString text = (_mode & M_ISDIR) ? i18nc("Write files into an existing folder", "&Write Into") : i18n("&Overwrite"); 00154 d->bOverwrite = new QPushButton(text, this); 00155 d->bOverwrite->setToolTip(i18n("Files and folders will be copied into the existing directory, alongside its existing contents.\nYou will be prompted again in case of a conflict with an existing file in the directory.")); 00156 connect(d->bOverwrite, SIGNAL(clicked()), this, SLOT(overwritePressed())); 00157 } 00158 00159 if (_mode & M_RESUME) { 00160 d->bResume = new QPushButton(i18n("&Resume"), this); 00161 connect(d->bResume, SIGNAL(clicked()), this, SLOT(resumePressed())); 00162 } 00163 00164 QVBoxLayout* pLayout = new QVBoxLayout(this); 00165 pLayout->addStrut(400); // makes dlg at least that wide 00166 00167 // User tries to overwrite a file with itself ? 00168 if (_mode & M_OVERWRITE_ITSELF) { 00169 QLabel *lb = new QLabel(i18n("This action would overwrite '%1' with itself.\n" 00170 "Please enter a new file name:", 00171 KStringHandler::csqueeze(d->src.pathOrUrl(), 100)), this); 00172 00173 d->bRename->setText(i18n("C&ontinue")); 00174 pLayout->addWidget(lb); 00175 } else if (_mode & M_OVERWRITE) { 00176 if (d->src.isLocalFile()) { 00177 d->srcItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->src); 00178 } else { 00179 UDSEntry srcUds; 00180 00181 srcUds.insert(UDSEntry::UDS_NAME, d->src.fileName()); 00182 srcUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeSrc); 00183 srcUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeSrc); 00184 srcUds.insert(UDSEntry::UDS_SIZE, sizeSrc); 00185 00186 d->srcItem = KFileItem(srcUds, d->src); 00187 } 00188 00189 if (d->dest.isLocalFile()) { 00190 d->destItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->dest); 00191 } else { 00192 UDSEntry destUds; 00193 00194 destUds.insert(UDSEntry::UDS_NAME, d->dest.fileName()); 00195 destUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeDest); 00196 destUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeDest); 00197 destUds.insert(UDSEntry::UDS_SIZE, sizeDest); 00198 00199 d->destItem = KFileItem(destUds, d->dest); 00200 } 00201 00202 d->m_srcPreview = createLabel(parent, QString(), false); 00203 d->m_destPreview = createLabel(parent, QString(), false); 00204 00205 d->m_srcPreview->setMinimumHeight(KIconLoader::SizeEnormous); 00206 d->m_destPreview->setMinimumHeight(KIconLoader::SizeEnormous); 00207 00208 d->m_srcPreview->setAlignment(Qt::AlignCenter); 00209 d->m_destPreview->setAlignment(Qt::AlignCenter); 00210 00211 d->m_srcPendingPreview = true; 00212 d->m_destPendingPreview = true; 00213 00214 // widget 00215 d->m_srcArea = createContainerLayout(parent, d->srcItem, d->m_srcPreview); 00216 d->m_destArea = createContainerLayout(parent, d->destItem, d->m_destPreview); 00217 00218 connect(d->m_srcArea->verticalScrollBar(), SIGNAL(valueChanged(int)), d->m_destArea->verticalScrollBar(), SLOT(setValue(int))); 00219 connect(d->m_destArea->verticalScrollBar(), SIGNAL(valueChanged(int)), d->m_srcArea->verticalScrollBar(), SLOT(setValue(int))); 00220 connect(d->m_srcArea->horizontalScrollBar(), SIGNAL(valueChanged(int)), d->m_destArea->horizontalScrollBar(), SLOT(setValue(int))); 00221 connect(d->m_destArea->horizontalScrollBar(), SIGNAL(valueChanged(int)), d->m_srcArea->horizontalScrollBar(), SLOT(setValue(int))); 00222 00223 // create layout 00224 QGridLayout* gridLayout = new QGridLayout(); 00225 pLayout->addLayout(gridLayout); 00226 00227 QLabel* titleLabel = new QLabel(i18n("This action will overwrite the destination."), this); 00228 00229 QLabel* srcTitle = createLabel(parent, i18n("Source"), true); 00230 QLabel* destTitle = createLabel(parent, i18n("Destination"), true); 00231 00232 QLabel* srcInfo = createSqueezedLabel(parent, d->src.pathOrUrl()); 00233 QLabel* destInfo = createSqueezedLabel(parent, d->dest.pathOrUrl()); 00234 00235 if (mtimeDest > mtimeSrc) { 00236 QLabel* warningLabel = new QLabel(i18n("Warning, the destination is more recent."), this); 00237 00238 gridLayout->addWidget(titleLabel, 0, 0, 1, 2); // takes the complete first line 00239 gridLayout->addWidget(warningLabel, 1, 0, 1, 2); 00240 gridLayout->setRowMinimumHeight(2, 15); // spacer 00241 00242 gridLayout->addWidget(srcTitle, 3, 0); 00243 gridLayout->addWidget(srcInfo, 4, 0); 00244 gridLayout->addWidget(d->m_srcArea, 5, 0); 00245 00246 gridLayout->addWidget(destTitle, 3, 1); 00247 gridLayout->addWidget(destInfo, 4, 1); 00248 gridLayout->addWidget(d->m_destArea, 5, 1); 00249 } else { 00250 gridLayout->addWidget(titleLabel, 0, 0, 1, 2); 00251 gridLayout->setRowMinimumHeight(1, 15); 00252 00253 gridLayout->addWidget(srcTitle, 2, 0); 00254 gridLayout->addWidget(srcInfo, 3, 0); 00255 gridLayout->addWidget(d->m_srcArea, 4, 0); 00256 00257 gridLayout->addWidget(destTitle, 2, 1); 00258 gridLayout->addWidget(destInfo, 3, 1); 00259 gridLayout->addWidget(d->m_destArea, 4, 1); 00260 } 00261 } else { 00262 // This is the case where we don't want to allow overwriting, the existing 00263 // file must be preserved (e.g. when renaming). 00264 QString sentence1; 00265 00266 if (mtimeDest < mtimeSrc) 00267 sentence1 = i18n("An older item named '%1' already exists.", d->dest.pathOrUrl()); 00268 else if (mtimeDest == mtimeSrc) 00269 sentence1 = i18n("A similar file named '%1' already exists.", d->dest.pathOrUrl()); 00270 else 00271 sentence1 = i18n("A more recent item named '%1' already exists.", d->dest.pathOrUrl()); 00272 00273 QLabel *lb = new KSqueezedTextLabel(sentence1, this); 00274 pLayout->addWidget(lb); 00275 } 00276 00277 if ((_mode != M_OVERWRITE_ITSELF) && (_mode != M_NORENAME)) { 00278 if (_mode == M_OVERWRITE) { 00279 pLayout->addSpacing(15); // spacer 00280 } 00281 00282 QLabel *lb2 = new QLabel(i18n("Rename:"), this); 00283 pLayout->addWidget(lb2); 00284 } 00285 00286 QHBoxLayout* layout2 = new QHBoxLayout(); 00287 pLayout->addLayout(layout2); 00288 00289 d->m_pLineEdit = new KLineEdit(this); 00290 layout2->addWidget(d->m_pLineEdit); 00291 00292 if (d->bRename) { 00293 const QString fileName = d->dest.fileName(); 00294 d->setRenameBoxText(KIO::decodeFileName(fileName)); 00295 00296 connect(d->m_pLineEdit, SIGNAL(textChanged(QString)), 00297 SLOT(enableRenameButton(QString))); 00298 00299 d->m_pLineEdit->setFocus(); 00300 } else { 00301 d->m_pLineEdit->hide(); 00302 } 00303 00304 if (d->bSuggestNewName) { 00305 layout2->addWidget(d->bSuggestNewName); 00306 setTabOrder(d->m_pLineEdit, d->bSuggestNewName); 00307 } 00308 00309 KSeparator* separator = new KSeparator(this); 00310 pLayout->addWidget(separator); 00311 00312 QHBoxLayout* layout = new QHBoxLayout(); 00313 pLayout->addLayout(layout); 00314 00315 layout->addStretch(1); 00316 00317 if (d->bApplyAll) { 00318 layout->addWidget(d->bApplyAll); 00319 setTabOrder(d->bApplyAll, d->bCancel); 00320 } 00321 00322 if (d->bRename) { 00323 layout->addWidget(d->bRename); 00324 setTabOrder(d->bRename, d->bCancel); 00325 } 00326 00327 if (d->bSkip) { 00328 layout->addWidget(d->bSkip); 00329 setTabOrder(d->bSkip, d->bCancel); 00330 } 00331 00332 if (d->bOverwrite) { 00333 layout->addWidget(d->bOverwrite); 00334 setTabOrder(d->bOverwrite, d->bCancel); 00335 } 00336 00337 if (d->bResume) { 00338 layout->addWidget(d->bResume); 00339 setTabOrder(d->bResume, d->bCancel); 00340 } 00341 00342 d->bCancel->setDefault(true); 00343 layout->addWidget(d->bCancel); 00344 00345 resize(sizeHint()); 00346 } 00347 00348 RenameDialog::~RenameDialog() 00349 { 00350 delete d; 00351 // no need to delete Pushbuttons,... qt will do this 00352 } 00353 00354 void RenameDialog::enableRenameButton(const QString &newDest) 00355 { 00356 if (newDest != KIO::decodeFileName(d->dest.fileName()) && !newDest.isEmpty()) { 00357 d->bRename->setEnabled(true); 00358 d->bRename->setDefault(true); 00359 00360 if (d->bOverwrite) { 00361 d->bOverwrite->setEnabled(false); // prevent confusion (#83114) 00362 } 00363 } else { 00364 d->bRename->setEnabled(false); 00365 00366 if (d->bOverwrite) { 00367 d->bOverwrite->setEnabled(true); 00368 } 00369 } 00370 } 00371 00372 KUrl RenameDialog::newDestUrl() 00373 { 00374 KUrl newDest(d->dest); 00375 QString fileName = d->m_pLineEdit->text(); 00376 00377 newDest.setFileName(KIO::encodeFileName(fileName)); 00378 00379 return newDest; 00380 } 00381 00382 KUrl RenameDialog::autoDestUrl() const 00383 { 00384 KUrl newDest(d->dest); 00385 KUrl destDirectory(d->dest); 00386 00387 destDirectory.setPath(destDirectory.directory()); 00388 newDest.setFileName(suggestName(destDirectory, d->dest.fileName())); 00389 00390 return newDest; 00391 } 00392 00393 void RenameDialog::cancelPressed() 00394 { 00395 done(R_CANCEL); 00396 } 00397 00398 // Rename 00399 void RenameDialog::renamePressed() 00400 { 00401 if (d->m_pLineEdit->text().isEmpty()) { 00402 return; 00403 } 00404 00405 if (d->bApplyAll && d->bApplyAll->isChecked()) { 00406 done(R_AUTO_RENAME); 00407 } else { 00408 KUrl u = newDestUrl(); 00409 00410 if (!u.isValid()) { 00411 KMessageBox::error(this, i18n("Malformed URL\n%1" , u.url())); 00412 return; 00413 } 00414 00415 done(R_RENAME); 00416 } 00417 } 00418 00419 QString RenameDialog::suggestName(const KUrl& baseURL, const QString& oldName) 00420 { 00421 QString dotSuffix, suggestedName; 00422 QString basename = oldName; 00423 const QChar spacer(' '); 00424 00425 //ignore dots at the beginning, that way "..aFile.tar.gz" will become "..aFile 1.tar.gz" instead of " 1..aFile.tar.gz" 00426 int index = basename.indexOf('.'); 00427 int continous = 0; 00428 while (continous == index) { 00429 index = basename.indexOf('.', index + 1); 00430 ++continous; 00431 } 00432 00433 if (index != -1) { 00434 dotSuffix = basename.mid(index); 00435 basename.truncate(index); 00436 } 00437 00438 int pos = basename.lastIndexOf(spacer); 00439 00440 if (pos != -1) { 00441 QString tmp = basename.mid(pos + 1); 00442 bool ok; 00443 int number = tmp.toInt(&ok); 00444 00445 if (!ok) { // ok there is no number 00446 suggestedName = basename + spacer + '1' + dotSuffix; 00447 } else { 00448 // yes there's already a number behind the spacer so increment it by one 00449 basename.replace(pos + 1, tmp.length(), QString::number(number + 1)); 00450 suggestedName = basename + dotSuffix; 00451 } 00452 } else // no spacer yet 00453 suggestedName = basename + spacer + "1" + dotSuffix ; 00454 00455 // Check if suggested name already exists 00456 bool exists = false; 00457 // TODO: network transparency. However, using NetAccess from a modal dialog 00458 // could be a problem, no? (given that it uses a modal widget itself....) 00459 if (baseURL.isLocalFile()) 00460 exists = QFileInfo(baseURL.toLocalFile(KUrl::AddTrailingSlash) + suggestedName).exists(); 00461 00462 if (!exists) 00463 return suggestedName; 00464 else // already exists -> recurse 00465 return suggestName(baseURL, suggestedName); 00466 } 00467 00468 // Propose button clicked 00469 void RenameDialog::suggestNewNamePressed() 00470 { 00471 /* no name to play with */ 00472 if (d->m_pLineEdit->text().isEmpty()) 00473 return; 00474 00475 KUrl destDirectory(d->dest); 00476 00477 destDirectory.setPath(destDirectory.directory()); 00478 d->setRenameBoxText(suggestName(destDirectory, d->m_pLineEdit->text())); 00479 00480 return; 00481 } 00482 00483 void RenameDialog::skipPressed() 00484 { 00485 if (d->bApplyAll && d->bApplyAll->isChecked()) { 00486 done(R_AUTO_SKIP); 00487 } else { 00488 done(R_SKIP); 00489 } 00490 } 00491 00492 void RenameDialog::autoSkipPressed() 00493 { 00494 done(R_AUTO_SKIP); 00495 } 00496 00497 void RenameDialog::overwritePressed() 00498 { 00499 if (d->bApplyAll && d->bApplyAll->isChecked()) { 00500 done(R_OVERWRITE_ALL); 00501 } else { 00502 done(R_OVERWRITE); 00503 } 00504 } 00505 00506 void RenameDialog::overwriteAllPressed() 00507 { 00508 done(R_OVERWRITE_ALL); 00509 } 00510 00511 void RenameDialog::resumePressed() 00512 { 00513 if (d->bApplyAll && d->bApplyAll->isChecked()) { 00514 done(R_RESUME_ALL); 00515 } else { 00516 done(R_RESUME); 00517 } 00518 } 00519 00520 void RenameDialog::resumeAllPressed() 00521 { 00522 done(R_RESUME_ALL); 00523 } 00524 00525 void RenameDialog::applyAllPressed() 00526 { 00527 if (d->bApplyAll && d->bApplyAll->isChecked()) { 00528 d->m_pLineEdit->setText(KIO::decodeFileName(d->dest.fileName())); 00529 d->m_pLineEdit->setEnabled(false); 00530 00531 if (d->bRename) { 00532 d->bRename->setEnabled(true); 00533 } 00534 00535 if (d->bSuggestNewName) { 00536 d->bSuggestNewName->setEnabled(false); 00537 } 00538 } else { 00539 d->m_pLineEdit->setEnabled(true); 00540 00541 if (d->bRename) { 00542 d->bRename->setEnabled(false); 00543 } 00544 00545 if (d->bSuggestNewName) { 00546 d->bSuggestNewName->setEnabled(true); 00547 } 00548 } 00549 } 00550 00551 void RenameDialog::showSrcIcon(const KFileItem& fileitem) 00552 { 00553 // The preview job failed, show a standard file icon. 00554 d->m_srcPendingPreview = false; 00555 d->m_srcPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height())); 00556 } 00557 00558 void RenameDialog::showDestIcon(const KFileItem& fileitem) 00559 { 00560 // The preview job failed, show a standard file icon. 00561 d->m_destPendingPreview = false; 00562 d->m_destPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height())); 00563 } 00564 00565 void RenameDialog::showSrcPreview(const KFileItem& fileitem, const QPixmap& pixmap) 00566 { 00567 Q_UNUSED(fileitem); 00568 00569 if (d->m_srcPendingPreview) { 00570 d->m_srcPreview->setPixmap(pixmap); 00571 d->m_srcPendingPreview = false; 00572 } 00573 } 00574 00575 void RenameDialog::showDestPreview(const KFileItem& fileitem, const QPixmap& pixmap) 00576 { 00577 Q_UNUSED(fileitem); 00578 00579 if (d->m_destPendingPreview) { 00580 d->m_destPreview->setPixmap(pixmap); 00581 d->m_destPendingPreview = false; 00582 } 00583 } 00584 00585 void RenameDialog::resizePanels() 00586 { 00587 // using QDesktopWidget geometry as Kephal isn't accessible here in kdelibs 00588 QSize screenSize = QApplication::desktop()->availableGeometry(this).size(); 00589 QSize halfSize = d->m_srcArea->widget()->sizeHint().expandedTo(d->m_destArea->widget()->sizeHint()); 00590 QSize currentSize = d->m_srcArea->size().expandedTo(d->m_destArea->size()); 00591 int maxHeightPossible = screenSize.height() - (size().height() - currentSize.height()); 00592 QSize maxHalfSize = QSize(screenSize.width() / qreal(2.1), maxHeightPossible * qreal(0.9)); 00593 00594 if (halfSize.height() > maxHalfSize.height() && 00595 halfSize.width() <= maxHalfSize.width() + d->m_srcArea->verticalScrollBar()->width()) 00596 { 00597 halfSize.rwidth() += d->m_srcArea->verticalScrollBar()->width(); 00598 maxHalfSize.rwidth() += d->m_srcArea->verticalScrollBar()->width(); 00599 } 00600 00601 d->m_srcArea->setMinimumSize(halfSize.boundedTo(maxHalfSize)); 00602 d->m_destArea->setMinimumSize(halfSize.boundedTo(maxHalfSize)); 00603 00604 KIO::PreviewJob* srcJob = KIO::filePreview(KFileItemList() << d->srcItem, 00605 QSize(d->m_srcPreview->width() * qreal(0.9), d->m_srcPreview->height())); 00606 srcJob->setScaleType(KIO::PreviewJob::Unscaled); 00607 00608 KIO::PreviewJob* destJob = KIO::filePreview(KFileItemList() << d->destItem, 00609 QSize(d->m_destPreview->width() * qreal(0.9), d->m_destPreview->height())); 00610 destJob->setScaleType(KIO::PreviewJob::Unscaled); 00611 00612 connect(srcJob, SIGNAL(gotPreview(KFileItem,QPixmap)), 00613 this, SLOT(showSrcPreview(KFileItem,QPixmap))); 00614 connect(destJob, SIGNAL(gotPreview(KFileItem,QPixmap)), 00615 this, SLOT(showDestPreview(KFileItem,QPixmap))); 00616 connect(srcJob, SIGNAL(failed(KFileItem)), 00617 this, SLOT(showSrcIcon(KFileItem))); 00618 connect(destJob, SIGNAL(failed(KFileItem)), 00619 this, SLOT(showDestIcon(KFileItem))); 00620 } 00621 00622 QScrollArea* RenameDialog::createContainerLayout(QWidget* parent, const KFileItem& item, QLabel* preview) 00623 { 00624 KFileItemList itemList; 00625 itemList << item; 00626 00627 // widget 00628 KFileMetaDataWidget* metaWidget = new KFileMetaDataWidget(this); 00629 00630 metaWidget->setReadOnly(true); 00631 metaWidget->setItems(itemList); 00632 connect(metaWidget, SIGNAL(metaDataRequestFinished(KFileItemList)), this, SLOT(resizePanels())); 00633 00634 // Encapsulate the MetaDataWidgets inside a container with stretch at the bottom. 00635 // This prevents that the meta data widgets get vertically stretched 00636 // in the case where the height of m_metaDataArea > m_metaDataWidget. 00637 00638 QWidget* widgetContainer = new QWidget(parent); 00639 QVBoxLayout* containerLayout = new QVBoxLayout(widgetContainer); 00640 00641 containerLayout->setContentsMargins(0, 0, 0, 0); 00642 containerLayout->setSpacing(0); 00643 containerLayout->addWidget(preview); 00644 containerLayout->addWidget(metaWidget); 00645 containerLayout->addStretch(1); 00646 00647 QScrollArea* metaDataArea = new QScrollArea(parent); 00648 00649 metaDataArea->setWidget(widgetContainer); 00650 metaDataArea->setWidgetResizable(true); 00651 metaDataArea->setFrameShape(QFrame::NoFrame); 00652 00653 return metaDataArea; 00654 } 00655 00656 QLabel* RenameDialog::createLabel(QWidget* parent, const QString& text, bool containerTitle) 00657 { 00658 QLabel* label = new QLabel(parent); 00659 00660 if (containerTitle) { 00661 QFont font = label->font(); 00662 font.setBold(true); 00663 label->setFont(font); 00664 } 00665 00666 label->setAlignment(Qt::AlignHCenter); 00667 label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); 00668 label->setText(text); 00669 00670 return label; 00671 } 00672 00673 KSqueezedTextLabel* RenameDialog::createSqueezedLabel(QWidget* parent, const QString& text) 00674 { 00675 KSqueezedTextLabel* label = new KSqueezedTextLabel(text, parent); 00676 00677 label->setAlignment(Qt::AlignHCenter); 00678 label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); 00679 00680 return label; 00681 } 00682 00683 #include "renamedialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed May 2 2012 18:21:24 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed May 2 2012 18:21:24 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.