PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/digikam-2.7.0/extra/kipi-plugins/imgurexport/imgurimageslist.cpp

#
C++ | 227 lines | 148 code | 45 blank | 34 comment | 19 complexity | 6163c56877d0d9359d8835bad8b8435b MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, GPL-3.0, GPL-2.0
  1. /* ============================================================
  2. *
  3. * This file is a part of kipi-plugins project
  4. * http://www.kipi-plugins.org
  5. *
  6. * Date : 2010-02-04
  7. * Description : a tool to export images to imgur.com
  8. *
  9. * Copyright (C) 2010-2012 by Marius Orcsik <marius at habarnam dot ro>
  10. *
  11. * This program is free software; you can redistribute it
  12. * and/or modify it under the terms of the GNU General
  13. * Public License as published by the Free Software Foundation;
  14. * either version 2, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * ============================================================ */
  22. #include "imgurimageslist.moc"
  23. #include "imgurimageslist.h"
  24. // Qt includes
  25. #include <QLabel>
  26. #include <QDesktopServices>
  27. // KDE includes
  28. #include <kdebug.h>
  29. #include <klocale.h>
  30. // Local includes
  31. #include "kpmetadata.h"
  32. namespace KIPIImgurExportPlugin
  33. {
  34. ImgurImagesList::ImgurImagesList(QWidget* const parent)
  35. : KPImagesList(parent)
  36. {
  37. setControlButtonsPlacement(KPImagesList::ControlButtonsBelow);
  38. setAllowDuplicate(false);
  39. setAllowRAW(false);
  40. listView()->setColumnLabel(KPImagesListView::Thumbnail, i18n("Thumbnail"));
  41. //listView()->setColumnLabel(KPImagesListView::Filename, i18n("File name"));
  42. listView()->setColumnLabel(static_cast<KIPIPlugins::KPImagesListView::ColumnType>(ImgurImagesList::Title),
  43. i18n("Submission title"));
  44. listView()->setColumnLabel(static_cast<KIPIPlugins::KPImagesListView::ColumnType>(ImgurImagesList::Description),
  45. i18n("Submission description"));
  46. listView()->setColumn(static_cast<KIPIPlugins::KPImagesListView::ColumnType>(ImgurImagesList::URL),
  47. i18n("Imgur URL"), true);
  48. listView()->setColumn(static_cast<KIPIPlugins::KPImagesListView::ColumnType>(ImgurImagesList::DeleteURL),
  49. i18n("Imgur Delete URL"), true);
  50. connect(listView(), SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
  51. this, SLOT(slotDoubleClick(QTreeWidgetItem*, int)));
  52. }
  53. ImgurImagesList::~ImgurImagesList()
  54. {
  55. }
  56. void ImgurImagesList::updateItemWidgets()
  57. {
  58. kDebug() << "update";
  59. }
  60. void ImgurImagesList::slotAddImages(const KUrl::List& list)
  61. {
  62. /* Replaces the KPImagesList::slotAddImages method, so that
  63. * ImgurImageListViewItems can be added instead of ImagesListViewItems */
  64. // Figure out which of the supplied URL's should actually be added and which
  65. // of them already exist.
  66. bool found;
  67. for (KUrl::List::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it)
  68. {
  69. KUrl imageUrl = *it;
  70. found = false;
  71. KPMetadata meta(imageUrl.toLocalFile());
  72. const QString sUrl = meta.getXmpTagString("Xmp.kipi.ImgurURL");
  73. const QString sDeleteUrl = meta.getXmpTagString("Xmp.kipi.ImgurDeleteURL");
  74. for (int i = 0; i < listView()->topLevelItemCount(); ++i)
  75. {
  76. ImgurImageListViewItem* currItem = dynamic_cast<ImgurImageListViewItem*>(listView()->topLevelItem(i));
  77. if (currItem && currItem->url() == imageUrl)
  78. {
  79. found = true;
  80. if (!sUrl.isEmpty())
  81. {
  82. currItem->setUrl(sUrl);
  83. }
  84. if (!sDeleteUrl.isEmpty())
  85. {
  86. currItem->setDeleteUrl(sDeleteUrl);
  87. }
  88. break;
  89. }
  90. }
  91. if (!found)
  92. {
  93. new ImgurImageListViewItem(listView(), imageUrl);
  94. }
  95. }
  96. // Duplicate the signalImageListChanged of the ImageWindow, to enable the
  97. // upload button again.
  98. emit signalImageListChanged();
  99. emit signalAddItems(list);
  100. }
  101. void ImgurImagesList::slotUploadError(const KUrl& /*localFile*/, ImgurError /*error*/)
  102. {
  103. // TODO
  104. }
  105. void ImgurImagesList::slotUploadSuccess(const KUrl& localFile, ImgurSuccess success)
  106. {
  107. for (int i = 0; i < listView()->topLevelItemCount(); ++i)
  108. {
  109. ImgurImageListViewItem* currItem = dynamic_cast<ImgurImageListViewItem*>(listView()->topLevelItem(i));
  110. if (currItem && currItem->url() == localFile)
  111. {
  112. if (!success.links.imgur_page.isEmpty())
  113. {
  114. const QString sUrl = success.links.imgur_page.toEncoded();
  115. currItem->setUrl(sUrl);
  116. }
  117. if (!success.links.delete_page.isEmpty())
  118. {
  119. const QString sDeleteUrl = success.links.delete_page.toEncoded();
  120. currItem->setDeleteUrl(sDeleteUrl);
  121. }
  122. break;
  123. }
  124. }
  125. }
  126. void ImgurImagesList::slotDoubleClick(QTreeWidgetItem* element, int i)
  127. {
  128. if (i == 3 || i == 4)
  129. {
  130. const QUrl url = QUrl (element->text(i));
  131. // need to check for delete url click - and ask user if he wants to remove the tags also
  132. QDesktopServices::openUrl(url);
  133. }
  134. }
  135. // ------------------------------------------------------------------------------------------------
  136. ImgurImageListViewItem::ImgurImageListViewItem(KPImagesListView* const view, const KUrl& url)
  137. : KPImagesListViewItem(view, url)
  138. {
  139. const QColor blue = QColor (0,0,255);
  140. setTextColor(3, blue);
  141. setTextColor(4, blue);
  142. }
  143. ImgurImageListViewItem::~ImgurImageListViewItem()
  144. {
  145. }
  146. void ImgurImageListViewItem::setTitle(const QString& str)
  147. {
  148. setText(ImgurImagesList::Title, str);
  149. m_Title = str;
  150. }
  151. QString ImgurImageListViewItem::Title() const
  152. {
  153. return m_Title;
  154. }
  155. void ImgurImageListViewItem::setDescription(const QString& str)
  156. {
  157. setText(ImgurImagesList::Description, str);
  158. m_Description = str;
  159. }
  160. QString ImgurImageListViewItem::Description() const
  161. {
  162. return m_Description;
  163. }
  164. void ImgurImageListViewItem::setUrl(const QString& str)
  165. {
  166. setText(ImgurImagesList::URL, str);
  167. m_Url = str;
  168. }
  169. QString ImgurImageListViewItem::Url() const
  170. {
  171. return m_Url;
  172. }
  173. void ImgurImageListViewItem::setDeleteUrl(const QString& str)
  174. {
  175. setText(ImgurImagesList::DeleteURL, str);
  176. m_deleteUrl = str;
  177. }
  178. QString ImgurImageListViewItem::deleteUrl() const
  179. {
  180. return m_deleteUrl;
  181. }
  182. } // namespace KIPIImgurExportPlugin