Changeset View
Changeset View
Standalone View
Standalone View
app/scangallery.cpp
Show First 20 Lines • Show All 466 Lines • ▼ Show 20 Line(s) | 442 | { | |||
---|---|---|---|---|---|
467 | } | 467 | } | ||
468 | else // image not loaded, show file info | 468 | else // image not loaded, show file info | ||
469 | { | 469 | { | ||
470 | if (format.isValid()) // if a valid image file | 470 | if (format.isValid()) // if a valid image file | ||
471 | { | 471 | { | ||
472 | if (isSubImage) // subimages don't show size | 472 | if (isSubImage) // subimages don't show size | ||
473 | { | 473 | { | ||
474 | item->setIcon(0, QIcon::fromTheme("edit-copy")); | 474 | item->setIcon(0, QIcon::fromTheme("edit-copy")); | ||
475 | item->setText(1, QString::null); | 475 | item->setText(1, QString()); | ||
476 | } | 476 | } | ||
477 | else | 477 | else | ||
478 | { | 478 | { | ||
479 | item->setIcon(0, QIcon::fromTheme("media-floppy")); | 479 | item->setIcon(0, QIcon::fromTheme("media-floppy")); | ||
480 | const KFileItem *kfi = item->fileItem(); | 480 | const KFileItem *kfi = item->fileItem(); | ||
481 | if (!kfi->isNull()) item->setText(1, (" " + KIO::convertSize(kfi->size()))); | 481 | if (!kfi->isNull()) item->setText(1, (" " + KIO::convertSize(kfi->size()))); | ||
482 | } | 482 | } | ||
483 | } | 483 | } | ||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Line(s) | 674 | { | |||
678 | if (!branchName.isEmpty()) // find in specified branch | 678 | if (!branchName.isEmpty()) // find in specified branch | ||
679 | { | 679 | { | ||
680 | item = findItemInBranch(branchName, relPath); | 680 | item = findItemInBranch(branchName, relPath); | ||
681 | } | 681 | } | ||
682 | else // assume the 1st/only branch | 682 | else // assume the 1st/only branch | ||
683 | { | 683 | { | ||
684 | item = findItemInBranch(branches().at(0), relPath); | 684 | item = findItemInBranch(branches().at(0), relPath); | ||
685 | } | 685 | } | ||
686 | if (item == nullptr) return; // not found in branch | 686 | if (item == nullptr) return; // not found in branch | ||
687 | 687 | | |||
688 | scrollToItem(item); | 688 | scrollToItem(item); | ||
689 | setCurrentItem(item); | 689 | setCurrentItem(item); | ||
690 | slotItemActivated(item); // load thumbnails, etc. | 690 | slotItemActivated(item); // load thumbnails, etc. | ||
691 | } | 691 | } | ||
692 | 692 | | |||
693 | void ScanGallery::loadImageForItem(FileTreeViewItem *item) | 693 | void ScanGallery::loadImageForItem(FileTreeViewItem *item) | ||
694 | { | 694 | { | ||
695 | if (item == nullptr) return; | 695 | if (item == nullptr) return; | ||
696 | const KFileItem *kfi = item->fileItem(); | 696 | const KFileItem *kfi = item->fileItem(); | ||
697 | if (kfi->isNull()) return; | 697 | if (kfi->isNull()) return; | ||
698 | 698 | | |||
699 | #ifdef DEBUG_LOADING | 699 | #ifdef DEBUG_LOADING | ||
700 | qDebug() << "loading" << item->url(); | 700 | qDebug() << "loading" << item->url(); | ||
701 | #endif // DEBUG_LOADING | 701 | #endif // DEBUG_LOADING | ||
702 | QString ret = QString::null; // no error so far | 702 | QString ret; // no error so far | ||
703 | 703 | | |||
704 | ImageFormat format = getImgFormat(item); // check for valid image format | 704 | ImageFormat format = getImgFormat(item); // check for valid image format | ||
705 | if (!format.isValid()) | 705 | if (!format.isValid()) | ||
706 | { | 706 | { | ||
707 | ret = i18n("Not a supported image format"); | 707 | ret = i18n("Not a supported image format"); | ||
708 | } | 708 | } | ||
709 | else // valid image | 709 | else // valid image | ||
710 | { | 710 | { | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 809 | { | |||
810 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | 810 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | ||
811 | if (curr == nullptr) { | 811 | if (curr == nullptr) { | ||
812 | return (nullptr); // no current item | 812 | return (nullptr); // no current item | ||
813 | } | 813 | } | ||
814 | if (curr->isDir()) { | 814 | if (curr->isDir()) { | ||
815 | return (nullptr); // is a directory | 815 | return (nullptr); // is a directory | ||
816 | } | 816 | } | ||
817 | 817 | | |||
818 | KookaImage *img = imageForItem(curr); // see if already loaded | 818 | KookaImage *img = imageForItem(curr); // see if already loaded | ||
819 | if (img == nullptr) { // no, try to do that | 819 | if (img == nullptr) { // no, try to do that | ||
820 | if (!loadOnDemand) { | 820 | if (!loadOnDemand) { | ||
821 | return (nullptr); // not loaded, and don't want to | 821 | return (nullptr); // not loaded, and don't want to | ||
822 | } | 822 | } | ||
823 | slotItemActivated(curr); // select/load this image | 823 | slotItemActivated(curr); // select/load this image | ||
824 | img = imageForItem(curr); // and get image for it | 824 | img = imageForItem(curr); // and get image for it | ||
825 | } | 825 | } | ||
826 | 826 | | |||
827 | return (img); | 827 | return (img); | ||
828 | } | 828 | } | ||
829 | 829 | | |||
830 | 830 | | |||
831 | QString ScanGallery::currentImageFileName() const | 831 | QString ScanGallery::currentImageFileName() const | ||
832 | { | 832 | { | ||
833 | QString result = ""; | 833 | QString result = ""; | ||
834 | 834 | | |||
835 | const FileTreeViewItem *curr = highlightedFileTreeViewItem(); | 835 | const FileTreeViewItem *curr = highlightedFileTreeViewItem(); | ||
836 | if (curr==nullptr) return (QString::null); | 836 | if (curr==nullptr) return (QString()); | ||
837 | 837 | | |||
838 | bool isLocal = false; | 838 | bool isLocal = false; | ||
839 | const QUrl u = curr->fileItem()->mostLocalUrl(isLocal); | 839 | const QUrl u = curr->fileItem()->mostLocalUrl(isLocal); | ||
840 | if (!isLocal) return (QString::null); | 840 | if (!isLocal) return (QString()); | ||
841 | return (u.toLocalFile()); | 841 | return (u.toLocalFile()); | ||
842 | } | 842 | } | ||
843 | 843 | | |||
844 | 844 | | |||
845 | bool ScanGallery::prepareToSave(const ImageMetaInfo *info) | 845 | bool ScanGallery::prepareToSave(const ImageMetaInfo *info) | ||
846 | { | 846 | { | ||
847 | if (info == nullptr) { | 847 | if (info == nullptr) { | ||
848 | //qDebug() << "no image info"; | 848 | //qDebug() << "no image info"; | ||
849 | } else { | 849 | } else { | ||
850 | //qDebug() << "type" << info->getImageType(); | 850 | //qDebug() << "type" << info->getImageType(); | ||
851 | } | 851 | } | ||
852 | 852 | | |||
853 | delete mSaver; mSaver = nullptr; // recreate with clean info | 853 | delete mSaver; mSaver = nullptr; // recreate with clean info | ||
854 | 854 | | |||
855 | // Resolve where to save the new image when it arrives | 855 | // Resolve where to save the new image when it arrives | ||
856 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | 856 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | ||
857 | if (curr == nullptr) { // into root if nothing is selected | 857 | if (curr == nullptr) { // into root if nothing is selected | ||
858 | FileTreeBranch *branch = branches().at(0); // there should be at least one | 858 | FileTreeBranch *branch = branches().at(0); // there should be at least one | ||
859 | if (branch != nullptr) { | 859 | if (branch != nullptr) { | ||
860 | // if user has created this???? | 860 | // if user has created this???? | ||
861 | curr = findItemInBranch(branch, i18n("Incoming/")); | 861 | curr = findItemInBranch(branch, i18n("Incoming/")); | ||
862 | if (curr == nullptr) { | 862 | if (curr == nullptr) { | ||
863 | curr = branch->root(); | 863 | curr = branch->root(); | ||
864 | } | 864 | } | ||
865 | } | 865 | } | ||
866 | 866 | | |||
867 | if (curr == nullptr) { | 867 | if (curr == nullptr) { | ||
868 | return (false); // should never happen | 868 | return (false); // should never happen | ||
869 | } | 869 | } | ||
870 | curr->setSelected(true); | 870 | curr->setSelected(true); | ||
871 | } | 871 | } | ||
872 | 872 | | |||
873 | mSavedTo = curr; // note for selecting later | 873 | mSavedTo = curr; // note for selecting later | ||
874 | 874 | | |||
875 | // Create the ImgSaver to use later | 875 | // Create the ImgSaver to use later | ||
876 | QUrl dir(itemDirectory(curr)); // where new image will go | 876 | QUrl dir(itemDirectory(curr)); // where new image will go | ||
877 | mSaver = new ImgSaver(dir); // create saver to use later | 877 | mSaver = new ImgSaver(dir); // create saver to use later | ||
878 | 878 | | |||
879 | if (info != nullptr) { // have image information, | 879 | if (info != nullptr) { // have image information, | ||
880 | // tell saver about it | 880 | // tell saver about it | ||
881 | ImgSaver::ImageSaveStatus stat = mSaver->setImageInfo(info); | 881 | ImgSaver::ImageSaveStatus stat = mSaver->setImageInfo(info); | ||
882 | if (stat == ImgSaver::SaveStatusCanceled) { | 882 | if (stat == ImgSaver::SaveStatusCanceled) { | ||
883 | return (false); | 883 | return (false); | ||
884 | } | 884 | } | ||
885 | } | 885 | } | ||
886 | 886 | | |||
887 | return (true); // all ready to save | 887 | return (true); // all ready to save | ||
888 | } | 888 | } | ||
889 | 889 | | |||
890 | QUrl ScanGallery::saveURL() const | 890 | QUrl ScanGallery::saveURL() const | ||
891 | { | 891 | { | ||
892 | if (mSaver == nullptr) { | 892 | if (mSaver == nullptr) { | ||
893 | return (QUrl()); | 893 | return (QUrl()); | ||
894 | } | 894 | } | ||
895 | // TODO: relative to root | 895 | // TODO: relative to root | ||
896 | return (mSaver->saveURL()); | 896 | return (mSaver->saveURL()); | ||
897 | } | 897 | } | ||
898 | 898 | | |||
899 | /* ----------------------------------------------------------------------- */ | 899 | /* ----------------------------------------------------------------------- */ | ||
900 | /* This slot takes a new scanned Picture and saves it. */ | 900 | /* This slot takes a new scanned Picture and saves it. */ | ||
901 | 901 | | |||
902 | void ScanGallery::addImage(const QImage *img, const ImageMetaInfo *info) | 902 | void ScanGallery::addImage(const QImage *img, const ImageMetaInfo *info) | ||
903 | { | 903 | { | ||
904 | if (img == nullptr) { | 904 | if (img == nullptr) { | ||
905 | return; // nothing to save! | 905 | return; // nothing to save! | ||
906 | } | 906 | } | ||
907 | //qDebug() << "size" << img->size() << "depth" << img->depth(); | 907 | //qDebug() << "size" << img->size() << "depth" << img->depth(); | ||
908 | 908 | | |||
909 | if (mSaver == nullptr) { | 909 | if (mSaver == nullptr) { | ||
910 | prepareToSave(nullptr); // if not done already | 910 | prepareToSave(nullptr); // if not done already | ||
911 | } | 911 | } | ||
912 | if (mSaver == nullptr) { | 912 | if (mSaver == nullptr) { | ||
913 | return; // should never happen | 913 | return; // should never happen | ||
914 | } | 914 | } | ||
915 | 915 | | |||
916 | ImgSaver::ImageSaveStatus isstat = mSaver->saveImage(img); | 916 | ImgSaver::ImageSaveStatus isstat = mSaver->saveImage(img); | ||
917 | // try to save the image | 917 | // try to save the image | ||
918 | QUrl lurl = mSaver->lastURL(); // record where it ended up | 918 | QUrl lurl = mSaver->lastURL(); // record where it ended up | ||
919 | 919 | | |||
920 | if (isstat != ImgSaver::SaveStatusOk && // image saving failed | 920 | if (isstat != ImgSaver::SaveStatusOk && // image saving failed | ||
921 | isstat != ImgSaver::SaveStatusCanceled) { // user cancelled, just ignore | 921 | isstat != ImgSaver::SaveStatusCanceled) { // user cancelled, just ignore | ||
922 | KMessageBox::error(this, xi18nc("@info", "Could not save the image<nl/><filename>%2</filename><nl/>%1", | 922 | KMessageBox::error(this, xi18nc("@info", "Could not save the image<nl/><filename>%2</filename><nl/>%1", | ||
923 | mSaver->errorString(isstat), | 923 | mSaver->errorString(isstat), | ||
924 | lurl.url(QUrl::PreferLocalFile)), | 924 | lurl.url(QUrl::PreferLocalFile)), | ||
925 | i18n("Image Save Error")); | 925 | i18n("Image Save Error")); | ||
926 | } | 926 | } | ||
927 | 927 | | |||
928 | delete mSaver; mSaver = nullptr; // now finished with this | 928 | delete mSaver; mSaver = nullptr; // now finished with this | ||
929 | 929 | | |||
930 | if (isstat == ImgSaver::SaveStatusOk) { // image was saved OK, | 930 | if (isstat == ImgSaver::SaveStatusOk) { // image was saved OK, | ||
931 | // select the new image | 931 | // select the new image | ||
932 | slotSetNextUrlToSelect(lurl); | 932 | slotSetNextUrlToSelect(lurl); | ||
933 | m_nextUrlToShow = lurl; | 933 | m_nextUrlToShow = lurl; | ||
934 | if (mSavedTo != nullptr) { | 934 | if (mSavedTo != nullptr) { | ||
935 | updateParent(mSavedTo); | 935 | updateParent(mSavedTo); | ||
936 | } | 936 | } | ||
937 | } | 937 | } | ||
938 | } | 938 | } | ||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | |||||
1092 | } | 1092 | } | ||
1093 | 1093 | | |||
1094 | void ScanGallery::slotUnloadItem(FileTreeViewItem *curr) | 1094 | void ScanGallery::slotUnloadItem(FileTreeViewItem *curr) | ||
1095 | { | 1095 | { | ||
1096 | if (curr == nullptr) { | 1096 | if (curr == nullptr) { | ||
1097 | return; | 1097 | return; | ||
1098 | } | 1098 | } | ||
1099 | 1099 | | |||
1100 | if (curr->isDir()) { // is a directory | 1100 | if (curr->isDir()) { // is a directory | ||
1101 | for (int i = 0; i < curr->childCount(); ++i) { | 1101 | for (int i = 0; i < curr->childCount(); ++i) { | ||
1102 | FileTreeViewItem *child = static_cast<FileTreeViewItem *>(curr->child(i)); | 1102 | FileTreeViewItem *child = static_cast<FileTreeViewItem *>(curr->child(i)); | ||
1103 | slotUnloadItem(child); // recursively unload contents | 1103 | slotUnloadItem(child); // recursively unload contents | ||
1104 | } | 1104 | } | ||
1105 | } else { // is a file/image | 1105 | } else { // is a file/image | ||
1106 | const KookaImage *image = imageForItem(curr); | 1106 | const KookaImage *image = imageForItem(curr); | ||
1107 | if (image == nullptr) { | 1107 | if (image == nullptr) { | ||
1108 | return; // ok, nothing to unload | 1108 | return; // ok, nothing to unload | ||
1109 | } | 1109 | } | ||
1110 | 1110 | | |||
1111 | if (image->subImagesCount() > 0) { // image with subimages | 1111 | if (image->subImagesCount() > 0) { // image with subimages | ||
1112 | while (curr->childCount() > 0) { // recursively unload subimages | 1112 | while (curr->childCount() > 0) { // recursively unload subimages | ||
1113 | FileTreeViewItem *child = static_cast<FileTreeViewItem *>(curr->takeChild(0)); | 1113 | FileTreeViewItem *child = static_cast<FileTreeViewItem *>(curr->takeChild(0)); | ||
1114 | slotUnloadItem(child); | 1114 | slotUnloadItem(child); | ||
1115 | delete child; | 1115 | delete child; | ||
1116 | } | 1116 | } | ||
1117 | } | 1117 | } | ||
1118 | 1118 | | |||
1119 | emit unloadImage(image); | 1119 | emit unloadImage(image); | ||
1120 | delete image; | 1120 | delete image; | ||
1121 | 1121 | | |||
1122 | curr->setClientData(nullptr); // clear image from item | 1122 | curr->setClientData(nullptr); // clear image from item | ||
1123 | slotDecorate(curr); | 1123 | slotDecorate(curr); | ||
1124 | } | 1124 | } | ||
1125 | } | 1125 | } | ||
1126 | 1126 | | |||
1127 | void ScanGallery::slotItemProperties() | 1127 | void ScanGallery::slotItemProperties() | ||
1128 | { | 1128 | { | ||
1129 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | 1129 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | ||
1130 | if (curr == nullptr) { | 1130 | if (curr == nullptr) { | ||
1131 | return; | 1131 | return; | ||
1132 | } | 1132 | } | ||
1133 | KPropertiesDialog::showDialog(curr->url(), this); | 1133 | KPropertiesDialog::showDialog(curr->url(), this); | ||
1134 | } | 1134 | } | ||
1135 | 1135 | | |||
1136 | /* ----------------------------------------------------------------------- */ | 1136 | /* ----------------------------------------------------------------------- */ | ||
1137 | 1137 | | |||
1138 | void ScanGallery::slotDeleteItems() | 1138 | void ScanGallery::slotDeleteItems() | ||
1139 | { | 1139 | { | ||
1140 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | 1140 | FileTreeViewItem *curr = highlightedFileTreeViewItem(); | ||
1141 | if (curr == nullptr) { | 1141 | if (curr == nullptr) { | ||
1142 | return; | 1142 | return; | ||
1143 | } | 1143 | } | ||
1144 | 1144 | | |||
1145 | QUrl urlToDel = curr->url(); // item to be deleted | 1145 | QUrl urlToDel = curr->url(); // item to be deleted | ||
1146 | bool isDir = curr->isDir(); // deleting a folder? | 1146 | bool isDir = curr->isDir(); // deleting a folder? | ||
1147 | QTreeWidgetItem *nextToSelect = curr->treeWidget()->itemBelow(curr); | 1147 | QTreeWidgetItem *nextToSelect = curr->treeWidget()->itemBelow(curr); | ||
1148 | // select this afterwards | 1148 | // select this afterwards | ||
1149 | QString s; | 1149 | QString s; | ||
1150 | QString dontAskKey; | 1150 | QString dontAskKey; | ||
1151 | if (isDir) { | 1151 | if (isDir) { | ||
1152 | s = xi18nc("@info", "Do you really want to permanently delete the folder<nl/>" | 1152 | s = xi18nc("@info", "Do you really want to permanently delete the folder<nl/>" | ||
1153 | "<filename>%1</filename><nl/>" | 1153 | "<filename>%1</filename><nl/>" | ||
1154 | "and all of its contents? It cannot be restored.", urlToDel.url(QUrl::PreferLocalFile)); | 1154 | "and all of its contents? It cannot be restored.", urlToDel.url(QUrl::PreferLocalFile)); | ||
Show All 20 Lines | |||||
1175 | { | 1175 | { | ||
1176 | KMessageBox::error(this, xi18nc("@info", "Could not delete the image or folder<nl/><filename>%2</filename><nl/>%1", | 1176 | KMessageBox::error(this, xi18nc("@info", "Could not delete the image or folder<nl/><filename>%2</filename><nl/>%1", | ||
1177 | job->errorString(), | 1177 | job->errorString(), | ||
1178 | urlToDel.url(QUrl::PreferLocalFile)), | 1178 | urlToDel.url(QUrl::PreferLocalFile)), | ||
1179 | i18n("File Delete Error")); | 1179 | i18n("File Delete Error")); | ||
1180 | return; | 1180 | return; | ||
1181 | } | 1181 | } | ||
1182 | 1182 | | |||
1183 | updateParent(curr); // update parent folder count | 1183 | updateParent(curr); // update parent folder count | ||
1184 | if (isDir) { // remove from the name combo | 1184 | if (isDir) { // remove from the name combo | ||
1185 | emit galleryDirectoryRemoved(curr->branch(), itemDirectoryRelative(curr)); | 1185 | emit galleryDirectoryRemoved(curr->branch(), itemDirectoryRelative(curr)); | ||
1186 | } | 1186 | } | ||
1187 | 1187 | | |||
1188 | #if 0 | 1188 | #if 0 | ||
1189 | if (nextToSelect != nullptr) { | 1189 | if (nextToSelect != nullptr) { | ||
1190 | setSelected(nextToSelect, true); | 1190 | setSelected(nextToSelect, true); | ||
1191 | } | 1191 | } | ||
1192 | // TODO: if doing the above, also need to signal to update thumbnail | 1192 | // TODO: if doing the above, also need to signal to update thumbnail | ||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |