File indexing completed on 2024-04-28 05:08:17

0001 /***************************************************************************
0002     Copyright (C) 2004-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #ifndef TELLICO_DBUSINTERFACE_H
0026 #define TELLICO_DBUSINTERFACE_H
0027 
0028 #include "../translators/translators.h"
0029 
0030 #include <QObject>
0031 #include <QUrl>
0032 #include <QStringList>
0033 
0034 // the entry id is typedef'd to an int, but we need to use an int for DBUS
0035 
0036 namespace Tellico {
0037 
0038 class MainWindow;
0039 
0040 class ApplicationInterface : public QObject {
0041 Q_OBJECT
0042 Q_CLASSINFO("D-Bus Interface", "org.kde.tellico")
0043 
0044 public:
0045   ApplicationInterface(MainWindow* parent);
0046 
0047 public Q_SLOTS:
0048   Q_SCRIPTABLE bool importTellico(const QString& file, const QString& action)
0049     { return importFile(Import::TellicoXML, QUrl::fromUserInput(file), actionType(action)); }
0050   Q_SCRIPTABLE bool importBibtex(const QString& file, const QString& action)
0051     { return importFile(Import::Bibtex, QUrl::fromUserInput(file), actionType(action)); }
0052   Q_SCRIPTABLE bool importMODS(const QString& file, const QString& action)
0053     { return importFile(Import::MODS, QUrl::fromUserInput(file), actionType(action)); }
0054   Q_SCRIPTABLE bool importRIS(const QString& file, const QString& action)
0055     { return importFile(Import::RIS, QUrl::fromUserInput(file), actionType(action)); }
0056   Q_SCRIPTABLE bool importPDF(const QString& file, const QString& action)
0057     { return importFile(Import::PDF, QUrl::fromUserInput(file), actionType(action)); }
0058 
0059   Q_SCRIPTABLE bool exportXML(const QString& file, bool filtered=false)
0060     { return exportCollection(Export::TellicoXML, QUrl::fromUserInput(file), filtered); }
0061   Q_SCRIPTABLE bool exportZip(const QString& file, bool filtered=false)
0062     { return exportCollection(Export::TellicoZip, QUrl::fromUserInput(file), filtered); }
0063   Q_SCRIPTABLE bool exportBibtex(const QString& file, bool filtered=false)
0064     { return exportCollection(Export::Bibtex, QUrl::fromUserInput(file), filtered); }
0065   Q_SCRIPTABLE bool exportHTML(const QString& file, bool filtered=false)
0066     { return exportCollection(Export::HTML, QUrl::fromUserInput(file), filtered); }
0067   Q_SCRIPTABLE bool exportCSV(const QString& file, bool filtered=false)
0068     { return exportCollection(Export::CSV, QUrl::fromUserInput(file), filtered); }
0069 
0070   Q_SCRIPTABLE QList<int> selectedEntries();
0071   Q_SCRIPTABLE QList<int> filteredEntries();
0072 
0073   Q_SCRIPTABLE virtual void openFile(const QString& file);
0074   Q_SCRIPTABLE virtual void setFilter(const QString& text);
0075   Q_SCRIPTABLE virtual bool showEntry(int id);
0076 
0077 private:
0078   virtual bool importFile(Import::Format format, const QUrl& url, Import::Action action);
0079   virtual bool exportCollection(Export::Format format, const QUrl& url, bool filtered);
0080 
0081   Import::Action actionType(const QString& actionName);
0082 
0083   MainWindow* m_mainWindow;
0084 };
0085 
0086 class CollectionInterface : public QObject {
0087 Q_OBJECT
0088 Q_CLASSINFO("D-Bus Interface", "org.kde.tellico")
0089 
0090 public:
0091   CollectionInterface(QObject* parent);
0092 
0093 public Q_SLOTS:
0094   Q_SCRIPTABLE int addEntry();
0095   Q_SCRIPTABLE bool removeEntry(int entryID);
0096 
0097   Q_SCRIPTABLE QStringList allValues(const QString& fieldName);
0098   Q_SCRIPTABLE QStringList entryValues(int entryID, const QString& fieldName);
0099   Q_SCRIPTABLE QStringList selectedBibtexKeys();
0100   Q_SCRIPTABLE QString entryBibtexKey(int entryID);
0101 
0102   Q_SCRIPTABLE bool setEntryValue(int entryID, const QString& fieldName, const QString& value);
0103   Q_SCRIPTABLE bool addEntryValue(int entryID, const QString& fieldName, const QString& value);
0104 };
0105 
0106 } // end namespace
0107 #endif