File indexing completed on 2022-09-27 13:41:19

0001 /*
0002 
0003     Copyright (C) 2001 The Kompany
0004           2002-2003 Ilya Konstantinov <kde-devel@future.shiny.co.il>
0005           2002-2003 Marcus Meissner <marcus@jet.franken.de>
0006           2003      Nadeem Hasan <nhasan@nadmm.com>
0007 
0008     This program is free software; you can redistribute it and/or modify
0009     it under the terms of the GNU General Public License as published by
0010     the Free Software Foundation; either version 2 of the License, or
0011     (at your option) any later version.
0012 
0013     This program is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016     GNU General Public License for more details.
0017 
0018     You should have received a copy of the GNU General Public License
0019     along with this program; if not, write to the Free Software
0020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0021 
0022 */
0023 #ifndef __kamera_h__
0024 #define __kamera_h__
0025 
0026 #include <KCModule>
0027 #include <gphoto2.h>
0028 #include <KPluginFactory>
0029 #include <QLoggingCategory>
0030 
0031 class QWidget;
0032 class QPushButton;
0033 class QListView;
0034 class QStandardItemModel;
0035 class QModelIndex;
0036 class QMenu;
0037 
0038 class KCamera;
0039 class KameraDeviceSelectDialog;
0040 class KConfig;
0041 class KActionCollection;
0042 class KToolBar;
0043 
0044 Q_DECLARE_LOGGING_CATEGORY(KAMERA_KCONTROL)
0045 
0046 class KKameraConfig : public KCModule
0047 {
0048     Q_OBJECT
0049     friend class KameraDeviceSelectDialog;
0050 
0051 public:
0052     explicit KKameraConfig(QWidget *parent, const QVariantList &);
0053     ~KKameraConfig() override;
0054 
0055     // KCModule interface methods
0056     void load() override;
0057     void save() override;
0058     void defaults() override;
0059     int buttons();
0060     QString quickHelp() const override;
0061 
0062 protected:
0063     QString suggestName(const QString &name);
0064 
0065 protected Q_SLOTS:
0066     void slot_deviceMenu(const QPoint &point);
0067     void slot_deviceSelected(const QModelIndex &index);
0068     void slot_addCamera();
0069     void slot_removeCamera();
0070     void slot_configureCamera();
0071     void slot_cameraSummary();
0072     void slot_testCamera();
0073     void slot_cancelOperation();
0074     void slot_error(const QString &message);
0075     void slot_error(const QString &message, const QString &details);
0076 
0077 private:
0078     void displayGPFailureDialogue();
0079     void displayGPSuccessDialogue();
0080     void displayCameraAbilities(const CameraAbilities &abilities);
0081     void populateDeviceListView();
0082     void beforeCameraOperation();
0083     void afterCameraOperation();
0084 
0085     // gphoto callbacks
0086     static void cbGPIdle(GPContext *context, void *data);
0087     static GPContextFeedback cbGPCancel(GPContext *context, void *data);
0088 
0089 private:
0090     using CameraDevicesMap = QMap<QString, KCamera *>;
0091 
0092     KConfig *m_config;
0093     CameraDevicesMap m_devices;
0094     bool m_cancelPending;
0095 
0096     // gphoto members
0097     GPContext *m_context;
0098 
0099     // widgets for the cameras listview
0100     QListView *m_deviceSel;
0101     QStandardItemModel *m_deviceModel;
0102     KActionCollection *m_actions;
0103     QPushButton *m_addCamera, *m_removeCamera, *m_testCamera, *m_configureCamera;
0104     KToolBar *m_toolbar;
0105     QMenu *m_devicePopup;
0106 
0107     // true if libgphoto2 was initialised successfully in
0108     // the constructor
0109     bool m_gpInitialised;
0110 };
0111 
0112 #endif