Changeset View
Changeset View
Standalone View
Standalone View
src/utils.cpp
Show First 20 Lines • Show All 784 Lines • ▼ Show 20 Line(s) | 761 | for (int i = 0; i < listCount; ++i) { | |||
---|---|---|---|---|---|
785 | } | 785 | } | ||
786 | } | 786 | } | ||
787 | } | 787 | } | ||
788 | } | 788 | } | ||
789 | 789 | | |||
790 | return hdays; | 790 | return hdays; | ||
791 | } | 791 | } | ||
792 | 792 | | |||
793 | void CalendarSupport::saveAttachments(const Akonadi::Item &item, QWidget *parentWidget) | | |||
794 | { | | |||
795 | Incidence::Ptr incidence = CalendarSupport::incidence(item); | | |||
796 | | ||||
797 | if (!incidence) { | | |||
798 | KMessageBox::sorry( | | |||
799 | parentWidget, | | |||
800 | i18n("No item selected.")); | | |||
801 | return; | | |||
802 | } | | |||
803 | | ||||
804 | Attachment::List attachments = incidence->attachments(); | | |||
805 | | ||||
806 | if (attachments.empty()) { | | |||
807 | return; | | |||
808 | } | | |||
809 | | ||||
810 | QString targetFile, targetDir; | | |||
811 | if (attachments.count() > 1) { | | |||
812 | // get the dir | | |||
813 | targetDir = QFileDialog::getExistingDirectory(parentWidget, i18n("Save Attachments To")); | | |||
814 | if (targetDir.isEmpty()) { | | |||
815 | return; | | |||
816 | } | | |||
817 | | ||||
818 | // we may not get a slash-terminated url out of KFileDialog | | |||
819 | if (!targetDir.endsWith(QLatin1Char('/'))) { | | |||
820 | targetDir.append(QLatin1Char('/')); | | |||
821 | } | | |||
822 | } else { | | |||
823 | // only one item, get the desired filename | | |||
824 | QString fileName = attachments.first()->label(); | | |||
825 | if (fileName.isEmpty()) { | | |||
826 | fileName = i18nc("filename for an unnamed attachment", "attachment.1"); | | |||
827 | } | | |||
828 | targetFile = QFileDialog::getSaveFileName(parentWidget, i18n("Save Attachment"), fileName); | | |||
829 | if (targetFile.isEmpty()) { | | |||
830 | return; | | |||
831 | } | | |||
832 | | ||||
833 | targetDir = QFileInfo(targetFile).absolutePath() + QLatin1Char('/'); | | |||
834 | } | | |||
835 | | ||||
836 | for (const Attachment::Ptr &attachment : qAsConst(attachments)) { | | |||
837 | targetFile = targetDir + attachment->label(); | | |||
838 | QUrl sourceUrl; | | |||
839 | if (attachment->isUri()) { | | |||
840 | sourceUrl = QUrl(attachment->uri()); | | |||
841 | } else { | | |||
842 | sourceUrl = QUrl::fromLocalFile(incidence->writeAttachmentToTempFile(attachment)); | | |||
843 | } | | |||
844 | // save the attachment url | | |||
845 | auto job = KIO::file_copy(sourceUrl, QUrl::fromLocalFile(targetFile)); | | |||
846 | if (!job->exec() && job->error()) { | | |||
847 | KMessageBox::error(parentWidget, job->errorString()); | | |||
848 | } | | |||
849 | } | | |||
850 | } | | |||
851 | | ||||
852 | QStringList CalendarSupport::categories(const KCalCore::Incidence::List &incidences) | 793 | QStringList CalendarSupport::categories(const KCalCore::Incidence::List &incidences) | ||
853 | { | 794 | { | ||
854 | QStringList cats, thisCats; | 795 | QStringList cats, thisCats; | ||
855 | // @TODO: For now just iterate over all incidences. In the future, | 796 | // @TODO: For now just iterate over all incidences. In the future, | ||
856 | // the list of categories should be built when reading the file. | 797 | // the list of categories should be built when reading the file. | ||
857 | for (const KCalCore::Incidence::Ptr &incidence : incidences) { | 798 | for (const KCalCore::Incidence::Ptr &incidence : incidences) { | ||
858 | thisCats = incidence->categories(); | 799 | thisCats = incidence->categories(); | ||
859 | const QStringList::ConstIterator send(thisCats.constEnd()); | 800 | const QStringList::ConstIterator send(thisCats.constEnd()); | ||
Show All 31 Lines |