1 /* ============================================================
2 *
3 * This file is a part of KDE project
4 *
5 *
6 * Date : 2010-11-15
7 * Description : a kipi plugin to export images to Yandex.Fotki web service
8 *
9 * Copyright (C) 2010 by Roman Tsisyk <roman at tsisyk 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 "plugin_yandexfotki.h"
24
25 // Qt includes
26
27 #include <QApplication>
28 #include <QAction>
29
30 // KDE includes
31
32 #include <kactioncollection.h>
33 #include <klocalizedstring.h>
34 #include <kpluginfactory.h>
35 #include <kwindowsystem.h>
36
37 // Libkipi includes
38
39 #include <KIPI/Interface>
40
41 // Local includes
42
43 #include "kputil.h"
44 #include "yfwindow.h"
45 #include "kipiplugins_debug.h"
46
47 namespace KIPIYandexFotkiPlugin
48 {
49
K_PLUGIN_FACTORY(Factory,registerPlugin<Plugin_YandexFotki> ();)50 K_PLUGIN_FACTORY( Factory, registerPlugin<Plugin_YandexFotki>(); )
51
52 Plugin_YandexFotki::Plugin_YandexFotki(QObject* const parent, const QVariantList&)
53 : Plugin(parent, "YandexFotki")
54 {
55 qCDebug(KIPIPLUGINS_LOG) << "Plugin_YandexFotki plugin loaded";
56
57 m_dlgExport = nullptr;
58 m_actionExport = nullptr;
59
60 setUiBaseName("kipiplugin_yandexfotkiui.rc");
61 setupXML();
62 }
63
~Plugin_YandexFotki()64 Plugin_YandexFotki::~Plugin_YandexFotki()
65 {
66 delete m_dlgExport;
67
68 removeTemporaryDir("yandexfotki");
69 }
70
setup(QWidget * const widget)71 void Plugin_YandexFotki::setup(QWidget* const widget)
72 {
73 Plugin::setup(widget);
74
75 setupActions();
76
77 if (!interface())
78 {
79 qCCritical(KIPIPLUGINS_LOG) << "Kipi interface is null!";
80 return;
81 }
82
83 m_actionExport->setEnabled(true);
84 }
85
setupActions()86 void Plugin_YandexFotki::setupActions()
87 {
88 setDefaultCategory(ExportPlugin);
89
90 m_actionExport = new QAction(this);
91 m_actionExport->setText(i18n("Export to &Yandex.Fotki..."));
92 // TODO: icon file
93 //m_actionExport->setIcon(QIcon::fromTheme("yandexfotki"));
94 m_actionExport->setIcon(QIcon::fromTheme(QString::fromLatin1("internet-web-browser")));
95 actionCollection()->setDefaultShortcut(m_actionExport, Qt::ALT + Qt::SHIFT + Qt::Key_Y);
96 m_actionExport->setEnabled(false);
97
98 connect(m_actionExport, SIGNAL(triggered(bool)),
99 this, SLOT(slotExport()));
100
101 addAction(QString::fromLatin1("Yandex.Fotki"), m_actionExport);
102 }
103
slotExport()104 void Plugin_YandexFotki::slotExport()
105 {
106 if (!m_dlgExport)
107 {
108 // This object will live forever, we will reuse it on future accesses
109 // to the plugin.
110 m_dlgExport = new YandexFotkiWindow(false, QApplication::activeWindow());
111 }
112 else
113 {
114 if (m_dlgExport->isMinimized())
115 KWindowSystem::unminimizeWindow(m_dlgExport->winId());
116
117 KWindowSystem::activateWindow(m_dlgExport->winId());
118 }
119
120 m_dlgExport->reactivate();
121 }
122
123 } // namespace KIPIYandexFotkiPlugin
124
125 #include "plugin_yandexfotki.moc"
126