summaryrefslogtreecommitdiffstats
path: root/tdenewstuff/engine.h
blob: 432f3b04ca8f14a504b9755e8e6da6b0aadd1ff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
    This file is part of KOrganizer.
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
    Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
#ifndef KNEWSTUFF_ENGINE_H
#define KNEWSTUFF_ENGINE_H

#include <tqmap.h>
#include <tqobject.h>
#include <tqstring.h>

#include "entry.h"
#include "provider.h"

namespace TDEIO { class Job; }

class TDENewStuff;

namespace KNS {

class DownloadDialog;
class UploadDialog;
class ProviderDialog;

/**
 * @short Central class combining all possible TDENewStuff operations.
 *
 * In most cases, Engine objects are built and used internally.
 * Using this class explicitely does however give fine-grained control about the
 * upload and download operations.
 *
 * @author Cornelius Schumacher (schumacher@kde.org)
 * \par Maintainer:
 * Josef Spillner (spillner@kde.org)
 */
class KDE_EXPORT Engine : public TQObject
{
    Q_OBJECT
    struct Private;
  public:
    /**
      Constructor.

      @param newStuff a TDENewStuff object
      @param type the Hotstuff data type such as "korganizer/calendar"
      @param parentWidget the parent window
    */
    Engine( TDENewStuff *newStuff, const TQString &type, TQWidget *parentWidget = 0 );
    /**
      Constructor.

      @param newStuff a TDENewStuff object
      @param type the Hotstuff data type such as "korganizer/calendar"
      @param providerList the URL of the provider list
      @param parentWidget the parent window
    */
    Engine( TDENewStuff *newStuff, const TQString &type, const TQString &providerList, TQWidget *parentWidget = 0 );

    /**
      Destructor.
    */
    virtual ~Engine();

    /**
      Returns the previously set data type.

      @return the Hotstuff data type
    */
    TQString type() const { return mType; }

    /**
      Returns the previously set parent widget.

      @return parent widget
    */
    TQWidget *parentWidget() const { return mParentWidget; }

    /**
      Initiates the download process, retrieving provider lists and invoking
      the download dialog.
    */
    void download();

    /**
      Initiates the upload process, invoking the provider selection dialog
      and the file upload dialog.

      @param fileName name of the payload data file
      @param previewName name of the preview image file
    */
    void upload( const TQString &fileName = TQString::null, const TQString &previewName = TQString::null );

    /**
      Downloads the specified data file.

      @param entry the Hotstuff data object to be downloaded
    */
    void download( Entry *entry );

    /**
      Asynchronous lookup of provider information such as upload and
      download locations, icon etc.

      @param provider the Hotstuff provider to request information from
    */
    void requestMetaInformation( Provider *provider );

    /**
      Uploads the specified data file to the provider-dependent location.

      @param entry the Hotstuff data object to be uploaded
    */
    void upload( Entry *entry );
    
    /**
    Ignores the return value of the install method. Used internally to
    avoid showing of the success/failure dialog when installation is done
    in another place, like in @ref TDENewStuffSecure
     */
    void ignoreInstallResult(bool ignore);   

  signals:
    /** Emitted when the upload has finished.
      @param result indicates the success/failure of the upload
    */
    void uploadFinished( bool result );
  protected slots:
    void getMetaInformation( Provider::List *providers );
    void selectUploadProvider( Provider::List *providers );

    void slotNewStuffJobData( TDEIO::Job *job, const TQByteArray &data );
    void slotNewStuffJobResult( TDEIO::Job *job );

    void slotDownloadJobResult( TDEIO::Job *job );

    void slotUploadPayloadJobResult( TDEIO::Job *job );
    void slotUploadPreviewJobResult (TDEIO::Job *job );
    void slotUploadMetaJobResult( TDEIO::Job *job );

  protected:
    bool createMetaFile( Entry * );
    
  private:
    TQWidget *mParentWidget;

    ProviderLoader *mProviderLoader;

    TQMap<TDEIO::Job *,TQString> mNewStuffJobData;
    TQMap<TDEIO::Job *,Provider *> mProviderJobs;

    TQPtrList<Entry> mNewStuffList;

    DownloadDialog *mDownloadDialog;
    UploadDialog *mUploadDialog;
    ProviderDialog *mProviderDialog;

    TQString mDownloadDestination;

    Provider *mUploadProvider;

    TQString mUploadMetaFile;
    TQString mUploadFile;
    TQString mPreviewFile;
    TQString mProviderList;

    Private* d;

    TQString mType;
};

}

#endif