• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
renamedialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
3 1999 - 2008 David Faure <faure@kde.org>
4 2001, 2006 Holger Freyther <freyther@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "kio/renamedialog.h"
23#include <stdio.h>
24#include <assert.h>
25
26#include <QtCore/QDate>
27#include <QtCore/QFileInfo>
28#include <QtGui/QCheckBox>
29#include <QtGui/QLabel>
30#include <QtGui/QLayout>
31#include <QtGui/QPixmap>
32#include <QtGui/QScrollArea>
33#include <QtGui/QScrollBar>
34#include <QtGui/QApplication>
35#include <QtGui/QDesktopWidget>
36#include <QtCore/QDir>
37
38#include <klineedit.h>
39#include <kmessagebox.h>
40#include <kpushbutton.h>
41#include <kio/global.h>
42#include <kio/udsentry.h>
43#include <kdialog.h>
44#include <klocale.h>
45#include <kglobal.h>
46#include <kdebug.h>
47#include <kurl.h>
48#include <kfileitem.h>
49#include <kmimetype.h>
50#include <kseparator.h>
51#include <kstringhandler.h>
52#include <kstandardguiitem.h>
53#include <kguiitem.h>
54#include <ksqueezedtextlabel.h>
55#include <kfilemetadatawidget.h>
56#include <previewjob.h>
57
58using namespace KIO;
59
61class RenameDialog::RenameDialogPrivate
62{
63public:
64 RenameDialogPrivate() {
65 bCancel = 0;
66 bRename = bSkip = bOverwrite = 0;
67 bResume = bSuggestNewName = 0;
68 bApplyAll = 0;
69 m_pLineEdit = 0;
70 m_srcPendingPreview = false;
71 m_destPendingPreview = false;
72 m_srcPreview = 0;
73 m_destPreview = 0;
74 }
75
76 void setRenameBoxText(const QString& fileName) {
77 // sets the text in file name line edit box, selecting the filename (but not the extension if there is one).
78 const QString extension = KMimeType::extractKnownExtension(fileName);
79 m_pLineEdit->setText(fileName);
80
81 if (!extension.isEmpty()) {
82 const int selectionLength = fileName.length() - extension.length() - 1;
83 m_pLineEdit->setSelection(0, selectionLength);
84 } else {
85 m_pLineEdit->selectAll();
86 }
87 }
88
89 KPushButton *bCancel;
90 QPushButton *bRename;
91 QPushButton *bSkip;
92 QPushButton *bOverwrite;
93 QPushButton *bResume;
94 QPushButton *bSuggestNewName;
95 QCheckBox *bApplyAll;
96 KLineEdit* m_pLineEdit;
97 KUrl src;
98 KUrl dest;
99 bool m_srcPendingPreview;
100 bool m_destPendingPreview;
101 QLabel* m_srcPreview;
102 QLabel* m_destPreview;
103 QScrollArea* m_srcArea;
104 QScrollArea* m_destArea;
105 KFileItem srcItem;
106 KFileItem destItem;
107};
108
109RenameDialog::RenameDialog(QWidget *parent, const QString & _caption,
110 const KUrl &_src, const KUrl &_dest,
111 RenameDialog_Mode _mode,
112 KIO::filesize_t sizeSrc,
113 KIO::filesize_t sizeDest,
114 time_t ctimeSrc,
115 time_t ctimeDest,
116 time_t mtimeSrc,
117 time_t mtimeDest)
118 : QDialog(parent), d(new RenameDialogPrivate)
119{
120 setObjectName("KIO::RenameDialog");
121
122 d->src = _src;
123 d->dest = _dest;
124
125 setWindowTitle(_caption);
126
127 d->bCancel = new KPushButton(KStandardGuiItem::cancel(), this);
128 connect(d->bCancel, SIGNAL(clicked()), this, SLOT(cancelPressed()));
129
130 if (_mode & M_MULTI) {
131 d->bApplyAll = new QCheckBox(i18n("Appl&y to All"), this);
132 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.")
133 : i18n("When this is checked the button pressed will be applied to all subsequent conflicts for the remainder of the current job."));
134 connect(d->bApplyAll, SIGNAL(clicked()), this, SLOT(applyAllPressed()));
135 }
136
137 if (!(_mode & M_NORENAME)) {
138 d->bRename = new QPushButton(i18n("&Rename"), this);
139 d->bRename->setEnabled(false);
140 d->bSuggestNewName = new QPushButton(i18n("Suggest New &Name"), this);
141 connect(d->bSuggestNewName, SIGNAL(clicked()), this, SLOT(suggestNewNamePressed()));
142 connect(d->bRename, SIGNAL(clicked()), this, SLOT(renamePressed()));
143 }
144
145 if ((_mode & M_MULTI) && (_mode & M_SKIP)) {
146 d->bSkip = new QPushButton(i18n("&Skip"), this);
147 d->bSkip->setToolTip((_mode & M_ISDIR) ? i18n("Do not copy or move this folder, skip to the next item instead")
148 : i18n("Do not copy or move this file, skip to the next item instead"));
149 connect(d->bSkip, SIGNAL(clicked()), this, SLOT(skipPressed()));
150 }
151
152 if (_mode & M_OVERWRITE) {
153 const QString text = (_mode & M_ISDIR) ? i18nc("Write files into an existing folder", "&Write Into") : i18n("&Overwrite");
154 d->bOverwrite = new QPushButton(text, this);
155 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."));
156 connect(d->bOverwrite, SIGNAL(clicked()), this, SLOT(overwritePressed()));
157 }
158
159 if (_mode & M_RESUME) {
160 d->bResume = new QPushButton(i18n("&Resume"), this);
161 connect(d->bResume, SIGNAL(clicked()), this, SLOT(resumePressed()));
162 }
163
164 QVBoxLayout* pLayout = new QVBoxLayout(this);
165 pLayout->addStrut(400); // makes dlg at least that wide
166
167 // User tries to overwrite a file with itself ?
168 if (_mode & M_OVERWRITE_ITSELF) {
169 QLabel *lb = new QLabel(i18n("This action would overwrite '%1' with itself.\n"
170 "Please enter a new file name:",
171 KStringHandler::csqueeze(d->src.pathOrUrl(), 100)), this);
172
173 d->bRename->setText(i18n("C&ontinue"));
174 pLayout->addWidget(lb);
175 } else if (_mode & M_OVERWRITE) {
176 if (d->src.isLocalFile()) {
177 d->srcItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->src);
178 } else {
179 UDSEntry srcUds;
180
181 srcUds.insert(UDSEntry::UDS_NAME, d->src.fileName());
182 srcUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeSrc);
183 srcUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeSrc);
184 srcUds.insert(UDSEntry::UDS_SIZE, sizeSrc);
185
186 d->srcItem = KFileItem(srcUds, d->src);
187 }
188
189 if (d->dest.isLocalFile()) {
190 d->destItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->dest);
191 } else {
192 UDSEntry destUds;
193
194 destUds.insert(UDSEntry::UDS_NAME, d->dest.fileName());
195 destUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeDest);
196 destUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeDest);
197 destUds.insert(UDSEntry::UDS_SIZE, sizeDest);
198
199 d->destItem = KFileItem(destUds, d->dest);
200 }
201
202 d->m_srcPreview = createLabel(parent, QString(), false);
203 d->m_destPreview = createLabel(parent, QString(), false);
204
205 d->m_srcPreview->setMinimumHeight(KIconLoader::SizeEnormous);
206 d->m_destPreview->setMinimumHeight(KIconLoader::SizeEnormous);
207
208 d->m_srcPreview->setAlignment(Qt::AlignCenter);
209 d->m_destPreview->setAlignment(Qt::AlignCenter);
210
211 d->m_srcPendingPreview = true;
212 d->m_destPendingPreview = true;
213
214 // widget
215 d->m_srcArea = createContainerLayout(parent, d->srcItem, d->m_srcPreview);
216 d->m_destArea = createContainerLayout(parent, d->destItem, d->m_destPreview);
217
218 connect(d->m_srcArea->verticalScrollBar(), SIGNAL(valueChanged(int)), d->m_destArea->verticalScrollBar(), SLOT(setValue(int)));
219 connect(d->m_destArea->verticalScrollBar(), SIGNAL(valueChanged(int)), d->m_srcArea->verticalScrollBar(), SLOT(setValue(int)));
220 connect(d->m_srcArea->horizontalScrollBar(), SIGNAL(valueChanged(int)), d->m_destArea->horizontalScrollBar(), SLOT(setValue(int)));
221 connect(d->m_destArea->horizontalScrollBar(), SIGNAL(valueChanged(int)), d->m_srcArea->horizontalScrollBar(), SLOT(setValue(int)));
222
223 // create layout
224 QGridLayout* gridLayout = new QGridLayout();
225 pLayout->addLayout(gridLayout);
226
227 QLabel* titleLabel = new QLabel(i18n("This action will overwrite the destination."), this);
228
229 QLabel* srcTitle = createLabel(parent, i18n("Source"), true);
230 QLabel* destTitle = createLabel(parent, i18n("Destination"), true);
231
232 QLabel* srcInfo = createSqueezedLabel(parent, d->src.pathOrUrl());
233 QLabel* destInfo = createSqueezedLabel(parent, d->dest.pathOrUrl());
234
235 if (mtimeDest > mtimeSrc) {
236 QLabel* warningLabel = new QLabel(i18n("Warning, the destination is more recent."), this);
237
238 gridLayout->addWidget(titleLabel, 0, 0, 1, 2); // takes the complete first line
239 gridLayout->addWidget(warningLabel, 1, 0, 1, 2);
240 gridLayout->setRowMinimumHeight(2, 15); // spacer
241
242 gridLayout->addWidget(srcTitle, 3, 0);
243 gridLayout->addWidget(srcInfo, 4, 0);
244 gridLayout->addWidget(d->m_srcArea, 5, 0);
245
246 gridLayout->addWidget(destTitle, 3, 1);
247 gridLayout->addWidget(destInfo, 4, 1);
248 gridLayout->addWidget(d->m_destArea, 5, 1);
249 } else {
250 gridLayout->addWidget(titleLabel, 0, 0, 1, 2);
251 gridLayout->setRowMinimumHeight(1, 15);
252
253 gridLayout->addWidget(srcTitle, 2, 0);
254 gridLayout->addWidget(srcInfo, 3, 0);
255 gridLayout->addWidget(d->m_srcArea, 4, 0);
256
257 gridLayout->addWidget(destTitle, 2, 1);
258 gridLayout->addWidget(destInfo, 3, 1);
259 gridLayout->addWidget(d->m_destArea, 4, 1);
260 }
261 } else {
262 // This is the case where we don't want to allow overwriting, the existing
263 // file must be preserved (e.g. when renaming).
264 QString sentence1;
265
266 if (mtimeDest < mtimeSrc)
267 sentence1 = i18n("An older item named '%1' already exists.", d->dest.pathOrUrl());
268 else if (mtimeDest == mtimeSrc)
269 sentence1 = i18n("A similar file named '%1' already exists.", d->dest.pathOrUrl());
270 else
271 sentence1 = i18n("A more recent item named '%1' already exists.", d->dest.pathOrUrl());
272
273 QLabel *lb = new KSqueezedTextLabel(sentence1, this);
274 pLayout->addWidget(lb);
275 }
276
277 if ((_mode != M_OVERWRITE_ITSELF) && (_mode != M_NORENAME)) {
278 if (_mode == M_OVERWRITE) {
279 pLayout->addSpacing(15); // spacer
280 }
281
282 QLabel *lb2 = new QLabel(i18n("Rename:"), this);
283 pLayout->addWidget(lb2);
284 }
285
286 QHBoxLayout* layout2 = new QHBoxLayout();
287 pLayout->addLayout(layout2);
288
289 d->m_pLineEdit = new KLineEdit(this);
290 layout2->addWidget(d->m_pLineEdit);
291
292 if (d->bRename) {
293 const QString fileName = d->dest.fileName();
294 d->setRenameBoxText(KIO::decodeFileName(fileName));
295
296 connect(d->m_pLineEdit, SIGNAL(textChanged(QString)),
297 SLOT(enableRenameButton(QString)));
298
299 d->m_pLineEdit->setFocus();
300 } else {
301 d->m_pLineEdit->hide();
302 }
303
304 if (d->bSuggestNewName) {
305 layout2->addWidget(d->bSuggestNewName);
306 setTabOrder(d->m_pLineEdit, d->bSuggestNewName);
307 }
308
309 KSeparator* separator = new KSeparator(this);
310 pLayout->addWidget(separator);
311
312 QHBoxLayout* layout = new QHBoxLayout();
313 pLayout->addLayout(layout);
314
315 layout->addStretch(1);
316
317 if (d->bApplyAll) {
318 layout->addWidget(d->bApplyAll);
319 setTabOrder(d->bApplyAll, d->bCancel);
320 }
321
322 if (d->bRename) {
323 layout->addWidget(d->bRename);
324 setTabOrder(d->bRename, d->bCancel);
325 }
326
327 if (d->bSkip) {
328 layout->addWidget(d->bSkip);
329 setTabOrder(d->bSkip, d->bCancel);
330 }
331
332 if (d->bOverwrite) {
333 layout->addWidget(d->bOverwrite);
334 setTabOrder(d->bOverwrite, d->bCancel);
335 }
336
337 if (d->bResume) {
338 layout->addWidget(d->bResume);
339 setTabOrder(d->bResume, d->bCancel);
340 }
341
342 d->bCancel->setDefault(true);
343 layout->addWidget(d->bCancel);
344
345 resize(sizeHint());
346}
347
348RenameDialog::~RenameDialog()
349{
350 delete d;
351 // no need to delete Pushbuttons,... qt will do this
352}
353
354void RenameDialog::enableRenameButton(const QString &newDest)
355{
356 if (newDest != KIO::decodeFileName(d->dest.fileName()) && !newDest.isEmpty()) {
357 d->bRename->setEnabled(true);
358 d->bRename->setDefault(true);
359
360 if (d->bOverwrite) {
361 d->bOverwrite->setEnabled(false); // prevent confusion (#83114)
362 }
363 } else {
364 d->bRename->setEnabled(false);
365
366 if (d->bOverwrite) {
367 d->bOverwrite->setEnabled(true);
368 }
369 }
370}
371
372KUrl RenameDialog::newDestUrl()
373{
374 KUrl newDest(d->dest);
375 QString fileName = d->m_pLineEdit->text();
376
377 newDest.setFileName(KIO::encodeFileName(fileName));
378
379 return newDest;
380}
381
382KUrl RenameDialog::autoDestUrl() const
383{
384 KUrl newDest(d->dest);
385 KUrl destDirectory(d->dest);
386
387 destDirectory.setPath(destDirectory.directory());
388 newDest.setFileName(suggestName(destDirectory, d->dest.fileName()));
389
390 return newDest;
391}
392
393void RenameDialog::cancelPressed()
394{
395 done(R_CANCEL);
396}
397
398// Rename
399void RenameDialog::renamePressed()
400{
401 if (d->m_pLineEdit->text().isEmpty()) {
402 return;
403 }
404
405 if (d->bApplyAll && d->bApplyAll->isChecked()) {
406 done(R_AUTO_RENAME);
407 } else {
408 KUrl u = newDestUrl();
409
410 if (!u.isValid()) {
411 KMessageBox::error(this, i18n("Malformed URL\n%1" , u.url()));
412 return;
413 }
414
415 done(R_RENAME);
416 }
417}
418
419QString RenameDialog::suggestName(const KUrl& baseURL, const QString& oldName)
420{
421 QString dotSuffix, suggestedName;
422 QString basename = oldName;
423 const QChar spacer(' ');
424
425 //ignore dots at the beginning, that way "..aFile.tar.gz" will become "..aFile 1.tar.gz" instead of " 1..aFile.tar.gz"
426 int index = basename.indexOf('.');
427 int continous = 0;
428 while (continous == index) {
429 index = basename.indexOf('.', index + 1);
430 ++continous;
431 }
432
433 if (index != -1) {
434 dotSuffix = basename.mid(index);
435 basename.truncate(index);
436 }
437
438 int pos = basename.lastIndexOf(spacer);
439
440 if (pos != -1) {
441 QString tmp = basename.mid(pos + 1);
442 bool ok;
443 int number = tmp.toInt(&ok);
444
445 if (!ok) { // ok there is no number
446 suggestedName = basename + spacer + '1' + dotSuffix;
447 } else {
448 // yes there's already a number behind the spacer so increment it by one
449 basename.replace(pos + 1, tmp.length(), QString::number(number + 1));
450 suggestedName = basename + dotSuffix;
451 }
452 } else // no spacer yet
453 suggestedName = basename + spacer + "1" + dotSuffix ;
454
455 // Check if suggested name already exists
456 bool exists = false;
457 // TODO: network transparency. However, using NetAccess from a modal dialog
458 // could be a problem, no? (given that it uses a modal widget itself....)
459 if (baseURL.isLocalFile())
460 exists = QFileInfo(baseURL.toLocalFile(KUrl::AddTrailingSlash) + suggestedName).exists();
461
462 if (!exists)
463 return suggestedName;
464 else // already exists -> recurse
465 return suggestName(baseURL, suggestedName);
466}
467
468// Propose button clicked
469void RenameDialog::suggestNewNamePressed()
470{
471 /* no name to play with */
472 if (d->m_pLineEdit->text().isEmpty())
473 return;
474
475 KUrl destDirectory(d->dest);
476
477 destDirectory.setPath(destDirectory.directory());
478 d->setRenameBoxText(suggestName(destDirectory, d->m_pLineEdit->text()));
479
480 return;
481}
482
483void RenameDialog::skipPressed()
484{
485 if (d->bApplyAll && d->bApplyAll->isChecked()) {
486 done(R_AUTO_SKIP);
487 } else {
488 done(R_SKIP);
489 }
490}
491
492void RenameDialog::autoSkipPressed()
493{
494 done(R_AUTO_SKIP);
495}
496
497void RenameDialog::overwritePressed()
498{
499 if (d->bApplyAll && d->bApplyAll->isChecked()) {
500 done(R_OVERWRITE_ALL);
501 } else {
502 done(R_OVERWRITE);
503 }
504}
505
506void RenameDialog::overwriteAllPressed()
507{
508 done(R_OVERWRITE_ALL);
509}
510
511void RenameDialog::resumePressed()
512{
513 if (d->bApplyAll && d->bApplyAll->isChecked()) {
514 done(R_RESUME_ALL);
515 } else {
516 done(R_RESUME);
517 }
518}
519
520void RenameDialog::resumeAllPressed()
521{
522 done(R_RESUME_ALL);
523}
524
525void RenameDialog::applyAllPressed()
526{
527 if (d->bApplyAll && d->bApplyAll->isChecked()) {
528 d->m_pLineEdit->setText(KIO::decodeFileName(d->dest.fileName()));
529 d->m_pLineEdit->setEnabled(false);
530
531 if (d->bRename) {
532 d->bRename->setEnabled(true);
533 }
534
535 if (d->bSuggestNewName) {
536 d->bSuggestNewName->setEnabled(false);
537 }
538 } else {
539 d->m_pLineEdit->setEnabled(true);
540
541 if (d->bRename) {
542 d->bRename->setEnabled(false);
543 }
544
545 if (d->bSuggestNewName) {
546 d->bSuggestNewName->setEnabled(true);
547 }
548 }
549}
550
551void RenameDialog::showSrcIcon(const KFileItem& fileitem)
552{
553 // The preview job failed, show a standard file icon.
554 d->m_srcPendingPreview = false;
555 d->m_srcPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height()));
556}
557
558void RenameDialog::showDestIcon(const KFileItem& fileitem)
559{
560 // The preview job failed, show a standard file icon.
561 d->m_destPendingPreview = false;
562 d->m_destPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height()));
563}
564
565void RenameDialog::showSrcPreview(const KFileItem& fileitem, const QPixmap& pixmap)
566{
567 Q_UNUSED(fileitem);
568
569 if (d->m_srcPendingPreview) {
570 d->m_srcPreview->setPixmap(pixmap);
571 d->m_srcPendingPreview = false;
572 }
573}
574
575void RenameDialog::showDestPreview(const KFileItem& fileitem, const QPixmap& pixmap)
576{
577 Q_UNUSED(fileitem);
578
579 if (d->m_destPendingPreview) {
580 d->m_destPreview->setPixmap(pixmap);
581 d->m_destPendingPreview = false;
582 }
583}
584
585void RenameDialog::resizePanels()
586{
587 // using QDesktopWidget geometry as Kephal isn't accessible here in kdelibs
588 QSize screenSize = QApplication::desktop()->availableGeometry(this).size();
589 QSize halfSize = d->m_srcArea->widget()->sizeHint().expandedTo(d->m_destArea->widget()->sizeHint());
590 QSize currentSize = d->m_srcArea->size().expandedTo(d->m_destArea->size());
591 int maxHeightPossible = screenSize.height() - (size().height() - currentSize.height());
592 QSize maxHalfSize = QSize(screenSize.width() / qreal(2.1), maxHeightPossible * qreal(0.9));
593
594 if (halfSize.height() > maxHalfSize.height() &&
595 halfSize.width() <= maxHalfSize.width() + d->m_srcArea->verticalScrollBar()->width())
596 {
597 halfSize.rwidth() += d->m_srcArea->verticalScrollBar()->width();
598 maxHalfSize.rwidth() += d->m_srcArea->verticalScrollBar()->width();
599 }
600
601 d->m_srcArea->setMinimumSize(halfSize.boundedTo(maxHalfSize));
602 d->m_destArea->setMinimumSize(halfSize.boundedTo(maxHalfSize));
603
604 KIO::PreviewJob* srcJob = KIO::filePreview(KFileItemList() << d->srcItem,
605 QSize(d->m_srcPreview->width() * qreal(0.9), d->m_srcPreview->height()));
606 srcJob->setScaleType(KIO::PreviewJob::Unscaled);
607
608 KIO::PreviewJob* destJob = KIO::filePreview(KFileItemList() << d->destItem,
609 QSize(d->m_destPreview->width() * qreal(0.9), d->m_destPreview->height()));
610 destJob->setScaleType(KIO::PreviewJob::Unscaled);
611
612 connect(srcJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
613 this, SLOT(showSrcPreview(KFileItem,QPixmap)));
614 connect(destJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
615 this, SLOT(showDestPreview(KFileItem,QPixmap)));
616 connect(srcJob, SIGNAL(failed(KFileItem)),
617 this, SLOT(showSrcIcon(KFileItem)));
618 connect(destJob, SIGNAL(failed(KFileItem)),
619 this, SLOT(showDestIcon(KFileItem)));
620}
621
622QScrollArea* RenameDialog::createContainerLayout(QWidget* parent, const KFileItem& item, QLabel* preview)
623{
624 KFileItemList itemList;
625 itemList << item;
626
627 // widget
628 KFileMetaDataWidget* metaWidget = new KFileMetaDataWidget(this);
629
630 metaWidget->setReadOnly(true);
631 metaWidget->setItems(itemList);
632 connect(metaWidget, SIGNAL(metaDataRequestFinished(KFileItemList)), this, SLOT(resizePanels()));
633
634 // Encapsulate the MetaDataWidgets inside a container with stretch at the bottom.
635 // This prevents that the meta data widgets get vertically stretched
636 // in the case where the height of m_metaDataArea > m_metaDataWidget.
637
638 QWidget* widgetContainer = new QWidget(parent);
639 QVBoxLayout* containerLayout = new QVBoxLayout(widgetContainer);
640
641 containerLayout->setContentsMargins(0, 0, 0, 0);
642 containerLayout->setSpacing(0);
643 containerLayout->addWidget(preview);
644 containerLayout->addWidget(metaWidget);
645 containerLayout->addStretch(1);
646
647 QScrollArea* metaDataArea = new QScrollArea(parent);
648
649 metaDataArea->setWidget(widgetContainer);
650 metaDataArea->setWidgetResizable(true);
651 metaDataArea->setFrameShape(QFrame::NoFrame);
652
653 return metaDataArea;
654}
655
656QLabel* RenameDialog::createLabel(QWidget* parent, const QString& text, bool containerTitle)
657{
658 QLabel* label = new QLabel(parent);
659
660 if (containerTitle) {
661 QFont font = label->font();
662 font.setBold(true);
663 label->setFont(font);
664 }
665
666 label->setAlignment(Qt::AlignHCenter);
667 label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
668 label->setText(text);
669
670 return label;
671}
672
673KSqueezedTextLabel* RenameDialog::createSqueezedLabel(QWidget* parent, const QString& text)
674{
675 KSqueezedTextLabel* label = new KSqueezedTextLabel(text, parent);
676
677 label->setAlignment(Qt::AlignHCenter);
678 label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
679
680 return label;
681}
682
683#include "renamedialog.moc"
KFileItemList
List of KFileItems, which adds a few helper methods to QList<KFileItem>.
Definition: kfileitem.h:675
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:46
KFileItem::Unknown
@ Unknown
Definition: kfileitem.h:48
KFileItem::pixmap
QPixmap pixmap(int _size, int _state=0) const
Returns a pixmap representing the file.
Definition: kfileitem.cpp:1014
KFileMetaDataWidget
Shows the meta data of one or more file items.
Definition: kfilemetadatawidget.h:47
KFileMetaDataWidget::setItems
void setItems(const KFileItemList &items)
Sets the items for which the meta data should be shown.
Definition: kfilemetadatawidget.cpp:335
KFileMetaDataWidget::setReadOnly
void setReadOnly(bool readOnly)
If set to true, data such as the comment, tag or rating cannot be changed by the user.
Definition: kfilemetadatawidget.cpp:351
KIO::PreviewJob
KIO Job to get a thumbnail picture.
Definition: previewjob.h:39
KIO::PreviewJob::setScaleType
void setScaleType(ScaleType type)
Sets the scale type for the generated preview.
Definition: previewjob.cpp:238
KIO::PreviewJob::Unscaled
@ Unscaled
The original size of the preview will be returned.
Definition: previewjob.h:51
KIO::RenameDialog::suggestNewNamePressed
void suggestNewNamePressed()
Definition: renamedialog.cpp:469
KIO::RenameDialog::~RenameDialog
~RenameDialog()
Definition: renamedialog.cpp:348
KIO::RenameDialog::overwritePressed
void overwritePressed()
Definition: renamedialog.cpp:497
KIO::RenameDialog::RenameDialog
RenameDialog(QWidget *parent, const QString &caption, const KUrl &src, const KUrl &dest, RenameDialog_Mode mode, KIO::filesize_t sizeSrc=KIO::filesize_t(-1), KIO::filesize_t sizeDest=KIO::filesize_t(-1), time_t ctimeSrc=time_t(-1), time_t ctimeDest=time_t(-1), time_t mtimeSrc=time_t(-1), time_t mtimeDest=time_t(-1))
Construct a "rename" dialog to let the user know that src is about to overwrite dest.
Definition: renamedialog.cpp:109
KIO::RenameDialog::suggestName
static QString suggestName(const KUrl &baseURL, const QString &oldName)
Given a directory path and a filename (which usually exists already), this function returns a suggest...
Definition: renamedialog.cpp:419
KIO::RenameDialog::overwriteAllPressed
void overwriteAllPressed()
Definition: renamedialog.cpp:506
KIO::RenameDialog::autoSkipPressed
void autoSkipPressed()
Definition: renamedialog.cpp:492
KIO::RenameDialog::renamePressed
void renamePressed()
Definition: renamedialog.cpp:399
KIO::RenameDialog::autoDestUrl
KUrl autoDestUrl() const
Definition: renamedialog.cpp:382
KIO::RenameDialog::skipPressed
void skipPressed()
Definition: renamedialog.cpp:483
KIO::RenameDialog::newDestUrl
KUrl newDestUrl()
Definition: renamedialog.cpp:372
KIO::RenameDialog::resumeAllPressed
void resumeAllPressed()
Definition: renamedialog.cpp:520
KIO::RenameDialog::resumePressed
void resumePressed()
Definition: renamedialog.cpp:511
KIO::RenameDialog::cancelPressed
void cancelPressed()
Definition: renamedialog.cpp:393
KIO::RenameDialog::enableRenameButton
void enableRenameButton(const QString &)
Definition: renamedialog.cpp:354
KIO::UDSEntry
Universal Directory Service.
Definition: udsentry.h:59
KIO::UDSEntry::UDS_CREATION_TIME
@ UDS_CREATION_TIME
The time the file was created.
Definition: udsentry.h:177
KIO::UDSEntry::UDS_MODIFICATION_TIME
@ UDS_MODIFICATION_TIME
The last time the file was modified.
Definition: udsentry.h:173
KIO::UDSEntry::UDS_SIZE
@ UDS_SIZE
Size of the file.
Definition: udsentry.h:144
KIO::UDSEntry::UDS_NAME
@ UDS_NAME
Filename - as displayed in directory listings etc.
Definition: udsentry.h:163
KIO::UDSEntry::insert
void insert(uint field, const QString &value)
insert field with numeric value
Definition: udsentry.cpp:94
KIconLoader::SizeEnormous
SizeEnormous
KLineEdit
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KMimeType::extractKnownExtension
static QString extractKnownExtension(const QString &fileName)
KPushButton
KSeparator
KSqueezedTextLabel
KUrl
KUrl::AddTrailingSlash
AddTrailingSlash
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::setFileName
void setFileName(const QString &_txt)
KUrl::directory
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
KUrl::isLocalFile
bool isLocalFile() const
KUrl::setPath
void setPath(const QString &path)
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
QDialog
QLabel
QPushButton
QWidget
global.h
kdebug.h
kdialog.h
kfileitem.h
kfilemetadatawidget.h
kglobal.h
kguiitem.h
klineedit.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
kmessagebox.h
kmimetype.h
kpushbutton.h
kseparator.h
ksqueezedtextlabel.h
kstandardguiitem.h
kstringhandler.h
kurl.h
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::encodeFileName
QString encodeFileName(const QString &str)
Encodes (from the text displayed to the real filename) This translates '/' into a "unicode fraction s...
Definition: global.cpp:146
KIO::decodeFileName
QString decodeFileName(const QString &str)
Decodes (from the filename to the text displayed) This doesn't do anything anymore,...
Definition: global.cpp:153
KIO::filePreview
PreviewJob * filePreview(const KFileItemList &items, int width, int height=0, int iconSize=0, int iconAlpha=70, bool scale=true, bool save=true, const QStringList *enabledPlugins=0)
Creates a PreviewJob to generate or retrieve a preview image for the given URL.
Definition: previewjob.cpp:755
KIO::R_RENAME
@ R_RENAME
Definition: renamedialog.h:61
KIO::R_AUTO_SKIP
@ R_AUTO_SKIP
Definition: renamedialog.h:61
KIO::R_OVERWRITE_ALL
@ R_OVERWRITE_ALL
Definition: renamedialog.h:61
KIO::R_OVERWRITE
@ R_OVERWRITE
Definition: renamedialog.h:61
KIO::R_AUTO_RENAME
@ R_AUTO_RENAME
Definition: renamedialog.h:61
KIO::R_RESUME
@ R_RESUME
Definition: renamedialog.h:61
KIO::R_SKIP
@ R_SKIP
Definition: renamedialog.h:61
KIO::R_CANCEL
@ R_CANCEL
Definition: renamedialog.h:61
KIO::R_RESUME_ALL
@ R_RESUME_ALL
Definition: renamedialog.h:61
KIO::RenameDialog_Mode
RenameDialog_Mode
M_OVERWRITE: We have an existing dest, show details about it and offer to overwrite it.
Definition: renamedialog.h:56
KIO::M_OVERWRITE_ITSELF
@ M_OVERWRITE_ITSELF
Definition: renamedialog.h:56
KIO::M_RESUME
@ M_RESUME
Definition: renamedialog.h:56
KIO::M_MULTI
@ M_MULTI
Definition: renamedialog.h:56
KIO::M_SKIP
@ M_SKIP
Definition: renamedialog.h:56
KIO::M_ISDIR
@ M_ISDIR
Definition: renamedialog.h:56
KIO::M_NORENAME
@ M_NORENAME
Definition: renamedialog.h:56
KIO::M_OVERWRITE
@ M_OVERWRITE
Definition: renamedialog.h:56
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KIO::number
QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition: global.cpp:63
KStandardGuiItem::cancel
KGuiItem cancel()
ok
KGuiItem ok()
label
QString label(StandardShortcut id)
KStringHandler::csqueeze
QString csqueeze(const QString &str, int maxlen=40)
previewjob.h
renamedialog.h
udsentry.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal