part.h 5.38 KB
Newer Older
1 2 3 4
/*
 * ark -- archiver for the KDE project
 *
 * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
5
 * Copyright (C) 2008-2009 Harald Hvaal <haraldhv@stud.ntnu.no>
6
 * Copyright (C) 2009 Raphael Kubo da Costa <rakuco@FreeBSD.org>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */
Henrique Pinto's avatar
Henrique Pinto committed
23 24 25
#ifndef PART_H
#define PART_H

26 27
#include "interface.h"

Henrique Pinto's avatar
Henrique Pinto committed
28
#include <KParts/Part>
Bhushan Shah's avatar
Bhushan Shah committed
29
#include <KParts/ReadWritePart>
30
#include <KParts/StatusBarExtension>
31
#include <KMessageWidget>
32

33
#include <QModelIndex>
Henrique Pinto's avatar
Henrique Pinto committed
34 35

class ArchiveModel;
36
class InfoPanel;
37

38
class KAboutData;
39
class KAbstractWidgetJobTracker;
40
class KJob;
41
class KToggleAction;
42 43 44 45

class QAction;
class QSplitter;
class QTreeView;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
46
class QTemporaryDir;
47
class QVBoxLayout;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
48 49
class QSignalMapper;
class QFileSystemWatcher;
50 51
class QGroupBox;
class QPlainTextEdit;
Henrique Pinto's avatar
Henrique Pinto committed
52

53 54 55
namespace Ark
{

56
class Part: public KParts::ReadWritePart, public Interface
Henrique Pinto's avatar
Henrique Pinto committed
57
{
58 59 60
    Q_OBJECT
    Q_INTERFACES(Interface)
public:
Ragnar Thomsen's avatar
Ragnar Thomsen committed
61 62 63 64
    enum OpenFileMode {
        Preview,
        OpenFile,
        OpenFileWith
65 66
    };

67
    Part(QWidget *parentWidget, QObject *parent, const QVariantList &);
68 69
    ~Part();

70 71
    static KAboutData *createAboutData();

72 73
    bool openFile() Q_DECL_OVERRIDE;
    bool saveFile() Q_DECL_OVERRIDE;
74

75
    bool isBusy() const Q_DECL_OVERRIDE;
76 77
    KConfigSkeleton *config() const Q_DECL_OVERRIDE;
    QList<Kerfuffle::SettingsPage*> settingsPages(QWidget *parent) const Q_DECL_OVERRIDE;
78

79 80 81 82 83 84 85
    /**
     * Validate the localFilePath() associated to this part.
     * If the file is not valid, an error message is displayed to the user.
     * @return Whether the localFilePath() can be loaded by the part.
     */
    bool isLocalFileValid();

86 87 88 89 90 91
    /**
     * Ask the user whether to overwrite @p targetFile, when creating a new archive with the same path.
     * @return True if the file has been successfully removed upon user's will. False otherwise.
     */
    bool confirmAndDelete(const QString& targetFile);

92
public slots:
93
    void extractSelectedFilesTo(const QString& localPath);
94 95 96 97

private slots:
    void slotLoadingStarted();
    void slotLoadingFinished(KJob *job);
Ragnar Thomsen's avatar
Ragnar Thomsen committed
98
    void slotOpenExtractedEntry(KJob*);
99
    void slotPreviewExtractedEntry(KJob* job);
Ragnar Thomsen's avatar
Ragnar Thomsen committed
100
    void slotOpenEntry(int mode);
101
    void slotError(const QString& errorMessage, const QString& details);
102 103
    void slotExtractArchive();
    void slotShowExtractionDialog();
104 105 106 107 108 109
    void slotExtractionDone(KJob*);
    void slotQuickExtractFiles(QAction*);
    void slotAddFiles();
    void slotAddFiles(const QStringList& files, const QString& path = QString());
    void slotAddDir();
    void slotAddFilesDone(KJob*);
Ragnar Thomsen's avatar
Ragnar Thomsen committed
110
    void slotTestingDone(KJob*);
111 112
    void slotDeleteFiles();
    void slotDeleteFilesDone(KJob*);
Ragnar Thomsen's avatar
Ragnar Thomsen committed
113
    void slotShowProperties();
114
    void slotShowContextMenu();
115
    void slotActivated(QModelIndex);
116
    void slotToggleInfoPanel(bool);
Raphael Kubo da Costa's avatar
Raphael Kubo da Costa committed
117
    void slotSaveAs();
118
    void updateActions();
119
    void updateQuickExtractMenu(QAction *extractAction);
120 121 122 123
    void selectionChanged();
    void adjustColumns();
    void setBusyGui();
    void setReadyGui();
124
    void setFileNameFromArchive();
Ragnar Thomsen's avatar
Ragnar Thomsen committed
125
    void slotWatchedFileModified(const QString& file);
126 127 128
    void slotShowComment();
    void slotAddComment();
    void slotCommentChanged();
Ragnar Thomsen's avatar
Ragnar Thomsen committed
129
    void slotTestArchive();
130 131 132 133

signals:
    void busy();
    void ready();
134
    void quit();
135 136 137 138

private:
    void setupView();
    void setupActions();
139 140
    bool isSingleFolderArchive() const;
    QString detectSubfolder() const;
141 142 143
    QList<QVariant> filesForIndexes(const QModelIndexList& list) const;
    QList<QVariant> filesAndRootNodesForIndexes(const QModelIndexList& list) const;
    QModelIndexList addChildren(const QModelIndexList &list) const;
144
    void registerJob(KJob *job);
145
    void displayMsgWidget(KMessageWidget::MessageType type, const QString& msg);
146 147 148

    ArchiveModel         *m_model;
    QTreeView            *m_view;
Bhushan Shah's avatar
Bhushan Shah committed
149
    QAction *m_previewAction;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
150 151
    QAction *m_openFileAction;
    QAction *m_openFileWithAction;
152
    QAction *m_extractArchiveAction;
153
    QAction *m_extractAction;
Bhushan Shah's avatar
Bhushan Shah committed
154 155 156 157
    QAction *m_addFilesAction;
    QAction *m_addDirAction;
    QAction *m_deleteFilesAction;
    QAction *m_saveAsAction;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
158
    QAction *m_propertiesAction;
159
    QAction *m_editCommentAction;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
160
    QAction *m_testArchiveAction;
161
    KToggleAction *m_showInfoPanelAction;
162
    InfoPanel            *m_infoPanel;
163
    QSplitter            *m_splitter;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
164
    QList<QTemporaryDir*>      m_tmpOpenDirList;
165
    bool                  m_busy;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
166
    OpenFileMode m_openFileMode;
167 168 169

    KAbstractWidgetJobTracker  *m_jobTracker;
    KParts::StatusBarExtension *m_statusBarExtension;
170
    QVBoxLayout *m_vlayout;
Ragnar Thomsen's avatar
Ragnar Thomsen committed
171 172
    QSignalMapper *m_signalMapper;
    QFileSystemWatcher *m_fileWatcher;
173 174 175
    QSplitter *m_commentSplitter;
    QGroupBox *m_commentBox;
    QPlainTextEdit *m_commentView;
176
    KMessageWidget *m_commentMsgWidget;
Henrique Pinto's avatar
Henrique Pinto committed
177 178
};

179 180
} // namespace Ark

Henrique Pinto's avatar
Henrique Pinto committed
181
#endif // PART_H