Commit 9138eb7d authored by David Jarvie's avatar David Jarvie
Browse files

Use mime type selection (by name and content) in calendar import dialogue

Display all text/calendar mime type files in the calendar import
dialogue, even when their file names are not *.ics or *.vcs, to allow
files within KAlarm calendar directories to be shown.
parent cd803e0c
...@@ -68,6 +68,7 @@ using namespace KCalendarCore; ...@@ -68,6 +68,7 @@ using namespace KCalendarCore;
#include <KJobWidgets> #include <KJobWidgets>
#include <KIO/StatJob> #include <KIO/StatJob>
#include <KIO/StoredTransferJob> #include <KIO/StoredTransferJob>
#include <KFileCustomDialog>
#include <QAction> #include <QAction>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
...@@ -75,7 +76,6 @@ using namespace KCalendarCore; ...@@ -75,7 +76,6 @@ using namespace KCalendarCore;
#include <QTimer> #include <QTimer>
#include <qglobal.h> #include <qglobal.h>
#include <QStandardPaths> #include <QStandardPaths>
#include <QFileDialog>
#include <QPushButton> #include <QPushButton>
#include <QTemporaryFile> #include <QTemporaryFile>
...@@ -780,11 +780,23 @@ QVector<KAEvent> getSortedActiveEvents(QObject* parent, AlarmListModel** model) ...@@ -780,11 +780,23 @@ QVector<KAEvent> getSortedActiveEvents(QObject* parent, AlarmListModel** model)
bool importAlarms(Resource& resource, QWidget* parent) bool importAlarms(Resource& resource, QWidget* parent)
{ {
qCDebug(KALARM_LOG) << "KAlarm::importAlarms" << resource.displayId(); qCDebug(KALARM_LOG) << "KAlarm::importAlarms" << resource.displayId();
const QList<QUrl> urls = QFileDialog::getOpenFileUrls( // Use KFileCustomDialog to allow files' mime types to be determined by
parent, // both file name and content, instead of QFileDialog which only looks at
i18nc("@title:window", "Import Calendar Files"), // files' names. This is needed in particular when importing an old KAlarm
lastImportUrl, // calendar directory, in order to list the calendar files within it, since
QStringLiteral("%1 (*.ics *.vcs);;%2 (*[^~])").arg(i18nc("@item:inlistbox File type selection filter", "Calendar files")).arg(i18nc("@item:inlistbox File type selection filter", "All files except backup files"))); // each calendar file name is simply the UID of the event within it, without
// a .ics extension.
AutoQPointer<KFileCustomDialog> dlg = new KFileCustomDialog(lastImportUrl, parent);
dlg->setWindowTitle(i18nc("@title:window", "Import Calendar Files"));
KFileWidget* widget = dlg->fileWidget();
widget->setOperationMode(KFileWidget::Opening);
widget->setMode(KFile::Files | KFile::ExistingOnly);
widget->setMimeFilter({QStringLiteral("text/calendar")});
dlg->setWindowModality(Qt::WindowModal);
dlg->exec();
if (!dlg)
return false;
const QList<QUrl> urls = widget->selectedUrls();
if (urls.isEmpty()) if (urls.isEmpty())
return false; return false;
lastImportUrl = urls[0].adjusted(QUrl::RemoveFilename); lastImportUrl = urls[0].adjusted(QUrl::RemoveFilename);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment