File indexing completed on 2022-09-27 13:43:09

0001 /* ============================================================
0002  *
0003  * This file is a part of KDE project
0004  *
0005  *
0006  * Date        : 2005-17-06
0007  * Description : a kipi plugin to export images to Flickr web service
0008  *
0009  * Copyright (C) 2005-2008 by Vardhman Jain <vardhman at gmail dot com>
0010  * Copyright (C) 2008-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * Copyright (C) 2009      by Luka Renko <lure at kubuntu dot org>
0012  *
0013  * This program is free software; you can redistribute it
0014  * and/or modify it under the terms of the GNU General
0015  * Public License as published by the Free Software Foundation;
0016  * either version 2, or (at your option) any later version.
0017  *
0018  * This program is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0021  * GNU General Public License for more details.
0022  *
0023  * ============================================================ */
0024 
0025 #include "plugin_flickr.h"
0026 
0027 //Qt includes
0028 
0029 #include <QApplication>
0030 
0031 // KDE includes
0032 
0033 #include <kactioncollection.h>
0034 #include <kpluginfactory.h>
0035 #include <kwindowsystem.h>
0036 
0037 // LibKIPI includes
0038 
0039 #include <KIPI/Interface>
0040 
0041 // Local includes
0042 
0043 #include "flickrwindow.h"
0044 #include "selectuserdlg.h"
0045 #include "kipiplugins_debug.h"
0046 
0047 namespace KIPIFlickrPlugin
0048 {
0049 
0050 K_PLUGIN_FACTORY(FlickrExportFactory, registerPlugin<Plugin_Flickr>();)
0051 
0052 Plugin_Flickr::Plugin_Flickr(QObject* const parent, const QVariantList& /*args*/)
0053     : Plugin(parent, "Flickr")
0054 {
0055     qCDebug(KIPIPLUGINS_LOG) << "Plugin_Flickr plugin loaded";
0056 
0057     setUiBaseName("kipiplugin_flickrui.rc");
0058     setupXML();
0059 
0060     m_actionFlickr = nullptr;
0061     m_action23     = nullptr;
0062 
0063     m_dlgFlickr    = nullptr;
0064     m_dlg23        = nullptr;
0065 
0066     selectFlickr   = nullptr;
0067     select23       = nullptr;
0068 }
0069 
0070 Plugin_Flickr::~Plugin_Flickr()
0071 {
0072     delete m_dlgFlickr;
0073     delete m_dlg23;
0074 
0075     delete selectFlickr;
0076     delete select23;
0077 }
0078 
0079 void Plugin_Flickr::setup(QWidget* const widget)
0080 {
0081     m_dlgFlickr = nullptr;
0082     m_dlg23     = nullptr;
0083 
0084     Plugin::setup(widget);
0085 
0086     if (!interface())
0087     {
0088         qCCritical(KIPIPLUGINS_LOG) << "Kipi interface is null!";
0089         return;
0090     }
0091 
0092     setupActions();
0093 }
0094 
0095 void Plugin_Flickr::setupActions()
0096 {
0097     setDefaultCategory(ExportPlugin);
0098 
0099     m_actionFlickr = new QAction(this);
0100     m_actionFlickr->setText(i18n("Export to Flick&r..."));
0101     m_actionFlickr->setIcon(QIcon::fromTheme(QString::fromLatin1("kipi-flickr")));
0102     actionCollection()->setDefaultShortcut(m_actionFlickr, Qt::ALT + Qt::SHIFT + Qt::Key_R);
0103 
0104     selectFlickr = new SelectUserDlg(nullptr, QString::fromLatin1("Flickr"));
0105 
0106     connect(m_actionFlickr, SIGNAL(triggered(bool)),
0107             this, SLOT(slotActivateFlickr()));
0108 
0109     addAction(QString::fromLatin1("flickrexport"), m_actionFlickr);
0110 /*
0111     m_action23 = new QAction(this);
0112     m_action23->setText(i18n("Export to &23..."));
0113     m_action23->setIcon(QIcon::fromTheme(QString::fromLatin1("kipi-hq")));
0114     actionCollection()->setDefaultShortcut(m_action23, Qt::ALT + Qt::SHIFT + Qt::Key_2);
0115 
0116     select23 = new SelectUserDlg(0,QString::fromLatin1("23"));
0117 
0118     connect(m_action23, SIGNAL(triggered(bool)),
0119             this, SLOT(slotActivate23()));
0120 
0121     addAction(QString::fromLatin1("23export"), m_action23);
0122 */
0123 }
0124 
0125 void Plugin_Flickr::slotActivateFlickr()
0126 {
0127     selectFlickr->reactivate();
0128 
0129     if (!m_dlgFlickr)
0130     {
0131         // We clean it up in the close button
0132         m_dlgFlickr = new FlickrWindow(QApplication::activeWindow(), QString::fromLatin1("Flickr"), selectFlickr);
0133     }
0134     else
0135     {
0136         if (m_dlgFlickr->isMinimized())
0137         {
0138             KWindowSystem::unminimizeWindow(m_dlgFlickr->winId());
0139         }
0140 
0141         KWindowSystem::activateWindow(m_dlgFlickr->winId());
0142     }
0143 
0144     m_dlgFlickr->reactivate();
0145 }
0146 
0147 void Plugin_Flickr::slotActivate23()
0148 {
0149     select23->reactivate();
0150 
0151     if (!m_dlg23)
0152     {
0153         // We clean it up in the close button
0154         m_dlg23 = new FlickrWindow(QApplication::activeWindow(), QString::fromLatin1("23"), select23);
0155     }
0156     else
0157     {
0158         if (m_dlg23->isMinimized())
0159         {
0160             KWindowSystem::unminimizeWindow(m_dlg23->winId());
0161         }
0162 
0163         KWindowSystem::activateWindow(m_dlg23->winId());
0164     }
0165 
0166     m_dlg23->reactivate();
0167 }
0168 
0169 } // namespace KIPIFlickrPlugin
0170 
0171 #include "plugin_flickr.moc"