1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2013-11-18
7  * Description : a tool to export items to Google web services
8  *
9  * Copyright (C) 2013      by Pankaj Kumar <me at panks dot me>
10  * Copyright (C) 2013-2020 by Caulier Gilles <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "gswidget.h"
25 
26 // Qt includes
27 
28 #include <QLabel>
29 #include <QSpinBox>
30 #include <QCheckBox>
31 #include <QGroupBox>
32 #include <QRadioButton>
33 #include <QButtonGroup>
34 #include <QGridLayout>
35 #include <QHBoxLayout>
36 #include <QVBoxLayout>
37 #include <QPushButton>
38 #include <QApplication>
39 #include <QComboBox>
40 
41 // KDE includes
42 
43 #include <klocalizedstring.h>
44 
45 namespace DigikamGenericGoogleServicesPlugin
46 {
47 
GSWidget(QWidget * const parent,DInfoInterface * const iface,const GoogleService & service,const QString & serviceName)48 GSWidget::GSWidget(QWidget* const parent,
49                    DInfoInterface* const iface,
50                    const GoogleService& service,
51                    const QString& serviceName)
52     : WSSettingsWidget(parent, iface, serviceName),
53       m_service       (service),
54       m_tagsBGrp      (nullptr)
55 {
56     QGroupBox* const leafBox = new QGroupBox(QLatin1String(""), getSettingsBox());
57 
58     if (m_service == GoogleService::GPhotoExport)
59     {
60         QGridLayout* leafLayout   = new QGridLayout(leafBox);
61         m_tagsBGrp                = new QButtonGroup(leafBox);
62         QSpacerItem* const spacer = new QSpacerItem(1, 10, QSizePolicy::Expanding, QSizePolicy::Minimum);
63         QLabel* const tagsLbl     = new QLabel(i18n("Tag path behavior :"), leafBox);
64 
65         QRadioButton* const leafTagsBtn     = new QRadioButton(i18n("Leaf tags only"), leafBox);
66         leafTagsBtn->setWhatsThis(i18n("Export only the leaf tags of tag hierarchies"));
67         QRadioButton* const splitTagsBtn    = new QRadioButton(i18n("Split tags"), leafBox);
68         splitTagsBtn->setWhatsThis(i18n("Export the leaf tag and all ancestors as single tags."));
69         QRadioButton* const combinedTagsBtn = new QRadioButton(i18n("Combined String"), leafBox);
70         combinedTagsBtn->setWhatsThis(i18n("Build a combined tag string."));
71 
72         m_tagsBGrp->addButton(leafTagsBtn,     GPTagLeaf);
73         m_tagsBGrp->addButton(splitTagsBtn,    GPTagSplit);
74         m_tagsBGrp->addButton(combinedTagsBtn, GPTagCombined);
75 
76         leafLayout->addItem(spacer,            0, 1, 1, 1);
77         leafLayout->addWidget(tagsLbl,         1, 1, 1, 1);
78         leafLayout->addWidget(leafTagsBtn,     2, 1, 1, 1);
79         leafLayout->addWidget(splitTagsBtn,    3, 1, 1, 1);
80         leafLayout->addWidget(combinedTagsBtn, 4, 1, 1, 1);
81 
82         addWidgetToSettingsBox(leafBox);
83     }
84 
85     switch (m_service)
86     {
87         case GoogleService::GPhotoImport:
88             getNewAlbmBtn()->hide();
89             getOptionsBox()->hide();
90             imagesList()->hide();
91             leafBox->hide();
92             getSizeBox()->hide(); // (Trung) Hide this option temporary, until factorization
93             break;
94 
95         case GoogleService::GDrive:
96             getOriginalCheckBox()->show();
97             getUploadBox()->hide();
98             getSizeBox()->hide();
99             leafBox->hide();
100             break;
101 
102         default:
103             getOriginalCheckBox()->show();
104             getUploadBox()->hide();
105             getSizeBox()->hide();
106             leafBox->hide();    // Google has removed this function in the current API V3.
107             getPhotoIdCheckBox()->show();
108             break;
109     }
110 }
111 
~GSWidget()112 GSWidget::~GSWidget()
113 {
114 }
115 
updateLabels(const QString & name,const QString & url)116 void GSWidget::updateLabels(const QString& name, const QString& url)
117 {
118     switch (m_service)
119     {
120         case GoogleService::GDrive:
121         {
122             QString web(QLatin1String("https://drive.google.com"));
123             getHeaderLbl()->setText(QString::fromLatin1(
124                 "<b><h2><a href='%1'>"
125                 "<font color=\"#9ACD32\">Google Drive</font>"
126                 "</a></h2></b>").arg(web));
127             break;
128         }
129 
130         default:
131         {
132             getHeaderLbl()->setText(QString::fromLatin1(
133                 "<b><h2><a href='https://photos.google.com/%1'>"
134                 "<font color=\"#9ACD32\">Google Photos</font>"
135                 "</a></h2></b>").arg(url));
136             break;
137         }
138     }
139 
140     if (name.isEmpty())
141     {
142         getUserNameLabel()->clear();
143     }
144     else
145     {
146         getUserNameLabel()->setText(QString::fromLatin1("<b>%1</b>").arg(name));
147     }
148 }
149 
150 } // namespace DigikamGenericGoogleServicesPlugin
151