Changeset View
Changeset View
Standalone View
Standalone View
src/kio/kfiledialog.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Line(s) | |||||
295 | 295 | | |||
296 | KFileDialog::~KFileDialog() | 296 | KFileDialog::~KFileDialog() | ||
297 | { | 297 | { | ||
298 | delete d; | 298 | delete d; | ||
299 | } | 299 | } | ||
300 | 300 | | |||
301 | void KFileDialog::setLocationLabel(const QString &text) | 301 | void KFileDialog::setLocationLabel(const QString &text) | ||
302 | { | 302 | { | ||
303 | if (d->native) { | 303 | if (d->w) { | ||
304 | return; // not available | | |||
305 | } | | |||
306 | d->w->setLocationLabel(text); | 304 | d->w->setLocationLabel(text); | ||
307 | } | 305 | } | ||
306 | } | ||||
308 | 307 | | |||
309 | void KFileDialog::setFilter(const QString &filter) | 308 | void KFileDialog::setFilter(const QString &filter) | ||
310 | { | 309 | { | ||
311 | if (d->native) { | 310 | if (d->native) { | ||
312 | d->native->filter = filter; | 311 | d->native->filter = filter; | ||
313 | return; | 312 | return; | ||
314 | } | 313 | } | ||
315 | d->w->setFilter(filter); | 314 | d->w->setFilter(filter); | ||
316 | } | 315 | } | ||
317 | 316 | | |||
318 | QString KFileDialog::currentFilter() const | 317 | QString KFileDialog::currentFilter() const | ||
319 | { | 318 | { | ||
320 | if (d->native) { | 319 | if (d->w) { | ||
321 | return QString(); // not available | | |||
322 | } | | |||
323 | return d->w->currentFilter(); | 320 | return d->w->currentFilter(); | ||
324 | } | 321 | } | ||
322 | return QString(); // not available | ||||
323 | } | ||||
325 | 324 | | |||
326 | void KFileDialog::setMimeFilter(const QStringList &mimeTypes, | 325 | void KFileDialog::setMimeFilter(const QStringList &mimeTypes, | ||
327 | const QString &defaultType) | 326 | const QString &defaultType) | ||
328 | { | 327 | { | ||
329 | d->w->setMimeFilter(mimeTypes, defaultType); | | |||
330 | | ||||
331 | if (d->native) { | 328 | if (d->native) { | ||
332 | QString allExtensions; | 329 | QString allExtensions; | ||
333 | QStringList filters = mime2KdeFilter(mimeTypes, &allExtensions); | 330 | QStringList filters = mime2KdeFilter(mimeTypes, &allExtensions); | ||
334 | if (defaultType.isEmpty() && (mimeTypes.count() > 1)) { | 331 | if (defaultType.isEmpty() && (mimeTypes.count() > 1)) { | ||
335 | filters.prepend(allExtensions + QLatin1Char('|') + i18n("All Supported Files")); | 332 | filters.prepend(allExtensions + QLatin1Char('|') + i18n("All Supported Files")); | ||
336 | } | 333 | } | ||
337 | d->native->filter = filters.join(QLatin1String("\n")); | 334 | d->native->filter = filters.join(QLatin1String("\n")); | ||
335 | return; | ||||
338 | } | 336 | } | ||
337 | d->w->setMimeFilter(mimeTypes, defaultType); | ||||
339 | } | 338 | } | ||
340 | 339 | | |||
341 | void KFileDialog::clearFilter() | 340 | void KFileDialog::clearFilter() | ||
342 | { | 341 | { | ||
343 | if (d->native) { | 342 | if (d->native) { | ||
344 | d->native->filter.clear(); | 343 | d->native->filter.clear(); | ||
345 | return; | 344 | return; | ||
346 | } | 345 | } | ||
Show All 16 Lines | |||||
363 | QMimeType KFileDialog::currentFilterMimeType() | 362 | QMimeType KFileDialog::currentFilterMimeType() | ||
364 | { | 363 | { | ||
365 | QMimeDatabase db; | 364 | QMimeDatabase db; | ||
366 | return db.mimeTypeForName(currentMimeFilter()); | 365 | return db.mimeTypeForName(currentMimeFilter()); | ||
367 | } | 366 | } | ||
368 | 367 | | |||
369 | void KFileDialog::setPreviewWidget(KPreviewWidgetBase *w) | 368 | void KFileDialog::setPreviewWidget(KPreviewWidgetBase *w) | ||
370 | { | 369 | { | ||
371 | if (d->native) { | 370 | if (d->w) { | ||
372 | return; | | |||
373 | } | | |||
374 | d->w->setPreviewWidget(w); | 371 | d->w->setPreviewWidget(w); | ||
375 | } | 372 | } | ||
373 | } | ||||
376 | 374 | | |||
377 | void KFileDialog::setInlinePreviewShown(bool show) | 375 | void KFileDialog::setInlinePreviewShown(bool show) | ||
378 | { | 376 | { | ||
379 | if (d->native) { | 377 | if (d->w) { | ||
380 | return; | | |||
381 | } | | |||
382 | d->w->setInlinePreviewShown(show); | 378 | d->w->setInlinePreviewShown(show); | ||
383 | } | 379 | } | ||
380 | } | ||||
384 | 381 | | |||
385 | // This is only used for the initial size when no configuration has been saved | 382 | // This is only used for the initial size when no configuration has been saved | ||
386 | QSize KFileDialog::sizeHint() const | 383 | QSize KFileDialog::sizeHint() const | ||
387 | { | 384 | { | ||
385 | if (d->w) { | ||||
388 | return d->w->dialogSizeHint(); | 386 | return d->w->dialogSizeHint(); | ||
389 | } | 387 | } | ||
388 | return QSize(); | ||||
389 | } | ||||
390 | 390 | | |||
391 | // This slot still exists mostly for compat purposes; for subclasses which reimplement slotOk | 391 | // This slot still exists mostly for compat purposes; for subclasses which reimplement slotOk | ||
392 | void KFileDialog::slotOk() | 392 | void KFileDialog::slotOk() | ||
393 | { | 393 | { | ||
394 | if (d->native) { | 394 | if (d->w) { | ||
395 | return; | | |||
396 | } | | |||
397 | d->w->slotOk(); | 395 | d->w->slotOk(); | ||
398 | } | 396 | } | ||
397 | } | ||||
399 | 398 | | |||
400 | // This slot still exists mostly for compat purposes; for subclasses which reimplement accept | 399 | // This slot still exists mostly for compat purposes; for subclasses which reimplement accept | ||
401 | void KFileDialog::accept() | 400 | void KFileDialog::accept() | ||
402 | { | 401 | { | ||
403 | if (d->native) { | 402 | if (d->w) { | ||
404 | return; | | |||
405 | } | | |||
406 | setResult(QDialog::Accepted); // keep old behavior; probably not needed though | 403 | setResult(QDialog::Accepted); // keep old behavior; probably not needed though | ||
407 | d->w->accept(); | 404 | d->w->accept(); | ||
408 | KConfigGroup cfgGroup(KSharedConfig::openConfig(), ConfigGroup); | 405 | KConfigGroup cfgGroup(KSharedConfig::openConfig(), ConfigGroup); | ||
409 | QDialog::accept(); | 406 | QDialog::accept(); | ||
410 | } | 407 | } | ||
408 | } | ||||
411 | 409 | | |||
412 | // This slot still exists mostly for compat purposes; for subclasses which reimplement slotCancel | 410 | // This slot still exists mostly for compat purposes; for subclasses which reimplement slotCancel | ||
413 | void KFileDialog::slotCancel() | 411 | void KFileDialog::slotCancel() | ||
414 | { | 412 | { | ||
415 | if (d->native) { | 413 | if (d->w) { | ||
416 | return; | | |||
417 | } | | |||
418 | d->w->slotCancel(); | 414 | d->w->slotCancel(); | ||
419 | reject(); | 415 | reject(); | ||
420 | } | 416 | } | ||
417 | } | ||||
421 | 418 | | |||
422 | void KFileDialog::setUrl(const QUrl &url, bool clearforward) | 419 | void KFileDialog::setUrl(const QUrl &url, bool clearforward) | ||
423 | { | 420 | { | ||
424 | if (d->native) { | 421 | if (d->native) { | ||
425 | d->native->selectedUrls.clear(); | 422 | d->native->selectedUrls.clear(); | ||
426 | d->native->selectedUrls.append(url); | 423 | d->native->selectedUrls.append(url); | ||
427 | return; | 424 | return; | ||
428 | } | 425 | } | ||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Line(s) | 574 | { | |||
596 | if (selectedFilter) { | 593 | if (selectedFilter) { | ||
597 | *selectedFilter = dlg.currentMimeFilter(); | 594 | *selectedFilter = dlg.currentMimeFilter(); | ||
598 | } | 595 | } | ||
599 | return dlg.selectedUrls(); | 596 | return dlg.selectedUrls(); | ||
600 | } | 597 | } | ||
601 | 598 | | |||
602 | void KFileDialog::setConfirmOverwrite(bool enable) | 599 | void KFileDialog::setConfirmOverwrite(bool enable) | ||
603 | { | 600 | { | ||
604 | if (operationMode() == KFileDialog::Saving) { | 601 | if (d->w && operationMode() == KFileDialog::Saving) { | ||
605 | d->w->setConfirmOverwrite(enable); | 602 | d->w->setConfirmOverwrite(enable); | ||
606 | } | 603 | } | ||
607 | } | 604 | } | ||
608 | 605 | | |||
609 | QUrl KFileDialog::getExistingDirectoryUrl(const QUrl &startDir, | 606 | QUrl KFileDialog::getExistingDirectoryUrl(const QUrl &startDir, | ||
610 | QWidget *parent, | 607 | QWidget *parent, | ||
kfunk: Should we rather check for `!d->w` here and below? Would make more sense IMO. | |||||
611 | const QString &caption) | 608 | const QString &caption) | ||
612 | { | 609 | { | ||
613 | return QFileDialog::getExistingDirectoryUrl(parent, caption, KFileDialogPrivate::Native::staticStartDir(startDir)); | 610 | return QFileDialog::getExistingDirectoryUrl(parent, caption, KFileDialogPrivate::Native::staticStartDir(startDir)); | ||
614 | } | 611 | } | ||
615 | 612 | | |||
616 | QString KFileDialog::getExistingDirectory(const QUrl &startDir, | 613 | QString KFileDialog::getExistingDirectory(const QUrl &startDir, | ||
617 | QWidget *parent, | 614 | QWidget *parent, | ||
618 | const QString &caption) | 615 | const QString &caption) | ||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Line(s) | 860 | { | |||
864 | if (d->native) { | 861 | if (d->native) { | ||
865 | return d->native->mode; | 862 | return d->native->mode; | ||
866 | } | 863 | } | ||
867 | return d->w->mode(); | 864 | return d->w->mode(); | ||
868 | } | 865 | } | ||
869 | 866 | | |||
870 | QPushButton *KFileDialog::okButton() const | 867 | QPushButton *KFileDialog::okButton() const | ||
871 | { | 868 | { | ||
869 | if (d->w) { | ||||
872 | return d->w->okButton(); | 870 | return d->w->okButton(); | ||
873 | } | 871 | } | ||
872 | return nullptr; | ||||
873 | } | ||||
874 | 874 | | |||
875 | QPushButton *KFileDialog::cancelButton() const | 875 | QPushButton *KFileDialog::cancelButton() const | ||
876 | { | 876 | { | ||
877 | if (d->w) { | ||||
877 | return d->w->cancelButton(); | 878 | return d->w->cancelButton(); | ||
878 | } | 879 | } | ||
aacid: nullptr here and in other places | |||||
880 | return nullptr; | ||||
881 | } | ||||
879 | 882 | | |||
880 | KUrlComboBox *KFileDialog::locationEdit() const | 883 | KUrlComboBox *KFileDialog::locationEdit() const | ||
881 | { | 884 | { | ||
885 | if (d->w) { | ||||
882 | return d->w->locationEdit(); | 886 | return d->w->locationEdit(); | ||
883 | } | 887 | } | ||
888 | return nullptr; | ||||
889 | } | ||||
884 | 890 | | |||
885 | KFileFilterCombo *KFileDialog::filterWidget() const | 891 | KFileFilterCombo *KFileDialog::filterWidget() const | ||
886 | { | 892 | { | ||
893 | if (d->w) { | ||||
887 | return d->w->filterWidget(); | 894 | return d->w->filterWidget(); | ||
888 | } | 895 | } | ||
896 | return nullptr; | ||||
897 | } | ||||
889 | 898 | | |||
890 | KActionCollection *KFileDialog::actionCollection() const | 899 | KActionCollection *KFileDialog::actionCollection() const | ||
891 | { | 900 | { | ||
901 | if (d->w) { | ||||
892 | return d->w->actionCollection(); | 902 | return d->w->actionCollection(); | ||
893 | } | 903 | } | ||
904 | return nullptr; | ||||
905 | } | ||||
894 | 906 | | |||
895 | void KFileDialog::setKeepLocation(bool keep) | 907 | void KFileDialog::setKeepLocation(bool keep) | ||
896 | { | 908 | { | ||
897 | if (d->native) { | 909 | if (d->w) { | ||
898 | return; | | |||
899 | } | | |||
900 | d->w->setKeepLocation(keep); | 910 | d->w->setKeepLocation(keep); | ||
901 | } | 911 | } | ||
912 | } | ||||
902 | 913 | | |||
903 | bool KFileDialog::keepsLocation() const | 914 | bool KFileDialog::keepsLocation() const | ||
904 | { | 915 | { | ||
905 | if (d->native) { | 916 | if (d->w) { | ||
906 | return false; | | |||
907 | } | | |||
908 | return d->w->keepsLocation(); | 917 | return d->w->keepsLocation(); | ||
909 | } | 918 | } | ||
919 | return false; | ||||
920 | } | ||||
910 | 921 | | |||
911 | void KFileDialog::setOperationMode(OperationMode mode) | 922 | void KFileDialog::setOperationMode(OperationMode mode) | ||
912 | { | 923 | { | ||
913 | if (d->native) { | 924 | if (d->native) { | ||
914 | d->native->operationMode = static_cast<KFileWidget::OperationMode>(mode); | 925 | d->native->operationMode = static_cast<KFileWidget::OperationMode>(mode); | ||
915 | } else { | 926 | } else { | ||
916 | d->w->setOperationMode(static_cast<KFileWidget::OperationMode>(mode)); | 927 | d->w->setOperationMode(static_cast<KFileWidget::OperationMode>(mode)); | ||
917 | } | 928 | } | ||
918 | } | 929 | } | ||
919 | 930 | | |||
920 | KFileDialog::OperationMode KFileDialog::operationMode() const | 931 | KFileDialog::OperationMode KFileDialog::operationMode() const | ||
921 | { | 932 | { | ||
922 | if (d->native) { | 933 | if (d->native) { | ||
923 | return static_cast<KFileDialog::OperationMode>(d->native->operationMode); | 934 | return static_cast<KFileDialog::OperationMode>(d->native->operationMode); | ||
924 | } | 935 | } | ||
925 | return static_cast<KFileDialog::OperationMode>(d->w->operationMode()); | 936 | return static_cast<KFileDialog::OperationMode>(d->w->operationMode()); | ||
926 | } | 937 | } | ||
927 | 938 | | |||
928 | void KFileDialog::keyPressEvent(QKeyEvent *e) | 939 | void KFileDialog::keyPressEvent(QKeyEvent *e) | ||
929 | { | 940 | { | ||
930 | if (d->native) { | 941 | if (d->w) { | ||
931 | return; | | |||
932 | } | | |||
933 | | ||||
934 | if (e->key() == Qt::Key_Escape) { | 942 | if (e->key() == Qt::Key_Escape) { | ||
935 | e->accept(); | 943 | e->accept(); | ||
936 | d->w->cancelButton()->animateClick(); | 944 | d->w->cancelButton()->animateClick(); | ||
937 | } else { | 945 | } else { | ||
938 | QDialog::keyPressEvent(e); | 946 | QDialog::keyPressEvent(e); | ||
939 | } | 947 | } | ||
940 | } | 948 | } | ||
949 | } | ||||
941 | 950 | | |||
942 | void KFileDialog::hideEvent(QHideEvent *e) | 951 | void KFileDialog::hideEvent(QHideEvent *e) | ||
943 | { | 952 | { | ||
944 | if (d->native) { | 953 | if (d->w) { | ||
945 | return; | | |||
946 | } | | |||
947 | | ||||
948 | KWindowConfig::saveWindowSize(windowHandle(), d->cfgGroup, KConfigBase::Persistent); | 954 | KWindowConfig::saveWindowSize(windowHandle(), d->cfgGroup, KConfigBase::Persistent); | ||
949 | 955 | | |||
950 | QDialog::hideEvent(e); | 956 | QDialog::hideEvent(e); | ||
951 | } | 957 | } | ||
958 | } | ||||
952 | 959 | | |||
953 | // static | 960 | // static | ||
954 | QUrl KFileDialog::getStartUrl(const QUrl &startDir, | 961 | QUrl KFileDialog::getStartUrl(const QUrl &startDir, | ||
955 | QString &recentDirClass) | 962 | QString &recentDirClass) | ||
956 | { | 963 | { | ||
957 | return KFileWidget::getStartUrl(startDir, recentDirClass); | 964 | return KFileWidget::getStartUrl(startDir, recentDirClass); | ||
958 | } | 965 | } | ||
959 | 966 | | |||
960 | void KFileDialog::setStartDir(const QUrl &directory) | 967 | void KFileDialog::setStartDir(const QUrl &directory) | ||
961 | { | 968 | { | ||
962 | if (KFileDialogPrivate::isNative()) { | 969 | if (KFileDialogPrivate::isNative()) { | ||
963 | KFileDialogPrivate::Native::s_startDir = directory; | 970 | KFileDialogPrivate::Native::s_startDir = directory; | ||
964 | } | 971 | } | ||
965 | KFileWidget::setStartDir(directory); | 972 | KFileWidget::setStartDir(directory); | ||
966 | } | 973 | } | ||
967 | 974 | | |||
968 | KToolBar *KFileDialog::toolBar() const | 975 | KToolBar *KFileDialog::toolBar() const | ||
969 | { | 976 | { | ||
977 | if (d->w) { | ||||
970 | return d->w->toolBar(); | 978 | return d->w->toolBar(); | ||
971 | } | 979 | } | ||
980 | return nullptr; | ||||
981 | } | ||||
972 | 982 | | |||
973 | KFileWidget *KFileDialog::fileWidget() | 983 | KFileWidget *KFileDialog::fileWidget() | ||
974 | { | 984 | { | ||
975 | return d->w; | 985 | return d->w; | ||
976 | } | 986 | } | ||
977 | 987 | | |||
978 | #ifdef Q_OS_WIN | 988 | #ifdef Q_OS_WIN | ||
979 | int KFileDialog::exec() | 989 | int KFileDialog::exec() | ||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |
Should we rather check for !d->w here and below? Would make more sense IMO.