1 /* ============================================================
2 *
3 * This file is a part of kipi-plugins project
4 *
5 *
6 * Date        : 2012-02-02
7 * Description : a plugin to export photos or videos to ImageShack web service
8 *
9 * Copyright (C) 2012 Dodon Victor <dodonvictor at gmail dot com>
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 
23 #include "imageshackwidget.h"
24 
25 // Qt includes
26 
27 #include <QLabel>
28 #include <QLineEdit>
29 #include <QGroupBox>
30 #include <QCheckBox>
31 #include <QRadioButton>
32 #include <QSpinBox>
33 #include <QStringList>
34 #include <QGridLayout>
35 #include <QHBoxLayout>
36 #include <QVBoxLayout>
37 #include <QComboBox>
38 #include <QApplication>
39 #include <QPushButton>
40 #include <QMimeDatabase>
41 #include <QMimeType>
42 
43 // KDE includes
44 
45 #include <klocalizedstring.h>
46 
47 // Libkipi includes
48 
49 #include <KIPI/UploadWidget>
50 #include <KIPI/ImageCollection>
51 
52 // Local includes
53 
54 #include "kipiplugins_debug.h"
55 #include "kpimageslist.h"
56 #include "imageshack.h"
57 #include "kpprogresswidget.h"
58 
59 namespace KIPIImageshackPlugin
60 {
61 
ImageshackWidget(QWidget * const parent,Imageshack * const imageshack,KIPI::Interface * const iface,const QString & pluginName)62 ImageshackWidget::ImageshackWidget(QWidget* const parent, Imageshack* const imageshack, KIPI::Interface* const iface, const QString& pluginName)
63     : KPSettingsWidget(parent, iface, pluginName),
64       m_imageshack(imageshack)
65 {
66 
67     m_imgList            = imagesList();
68     m_headerLbl          = getHeaderLbl();
69     m_accountNameLbl     = getUserNameLabel();
70     m_chgRegCodeBtn      = getChangeUserBtn();
71     m_reloadGalleriesBtn = getReloadBtn();
72     m_galleriesCob       = getAlbumsCoB();
73     m_progressBar        = progressBar();
74 
75     connect(m_reloadGalleriesBtn, SIGNAL(clicked()),
76             this, SLOT(slotReloadGalleries()));
77 
78     QGroupBox* const tagsBox      = new QGroupBox(QString::fromLatin1(""), getSettingsBox());
79     QGridLayout* const tagsLayout = new QGridLayout(tagsBox);
80 
81     m_privateImagesChb = new QCheckBox(tagsBox);
82     m_privateImagesChb->setText(i18n("Make private"));
83     m_privateImagesChb->setChecked(false);
84 
85     m_tagsFld             = new QLineEdit(tagsBox);
86     QLabel* const tagsLbl = new QLabel(i18n("Tags (optional):"), tagsBox);
87 
88     m_remBarChb           = new QCheckBox(i18n("Remove information bar on thumbnails"));
89     m_remBarChb->setChecked(false);
90 
91     tagsLayout->addWidget(m_privateImagesChb, 0, 0);
92     tagsLayout->addWidget(tagsLbl,            1, 0);
93     tagsLayout->addWidget(m_tagsFld,          1, 1);
94 
95     addWidgetToSettingsBox(tagsBox);
96 
97     getUploadBox()->hide();
98     getSizeBox()->hide();
99 
100     updateLabels();
101 }
102 
~ImageshackWidget()103 ImageshackWidget::~ImageshackWidget()
104 {
105 }
106 
updateLabels(const QString &,const QString &)107 void ImageshackWidget::updateLabels(const QString& /*name*/, const QString& /*url*/)
108 {
109     if (m_imageshack->loggedIn())
110     {
111         m_accountNameLbl->setText(m_imageshack->username());
112         //m_accountEmailLbl->setText(m_imageshack->email());
113     }
114     else
115     {
116         m_accountNameLbl->clear();
117         //m_accountEmailLbl->clear();
118     }
119 }
120 
slotGetGalleries(const QStringList & gTexts,const QStringList & gNames)121 void ImageshackWidget::slotGetGalleries(const QStringList &gTexts, const QStringList &gNames)
122 {
123     m_galleriesCob->clear();
124 
125     m_galleriesCob->addItem(i18nc("@item:inlistbox", "Add to root folder"),
126                             QString::fromLatin1("--add-to-root--"));
127 
128     m_galleriesCob->addItem(i18nc("@item:inlistbox", "Create new gallery"),
129                             QString::fromLatin1("--new-gallery--"));
130 
131     // TODO check if the lists have the same size
132     for (int i = 0; i < gTexts.size(); ++i)
133     {
134         qCDebug(KIPIPLUGINS_LOG) << "gTexts is "<<gTexts[i] << " gNames is "<<gNames[i];
135         m_galleriesCob->addItem(gTexts[i], gNames[i]);
136     }
137 
138 //     slotEnableNewGalleryLE(m_galleriesCob->currentIndex());
139 }
140 
slotReloadGalleries()141 void ImageshackWidget::slotReloadGalleries()
142 {
143     emit signalReloadGalleries();
144 }
145 
146 }  // namespace KIPIImageshackPlugin
147