File: mcontroller.h

package info (click to toggle)
classified-ads 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,772 kB
  • sloc: cpp: 34,291; tcl: 1,175; xml: 64; makefile: 40
file content (246 lines) | stat: -rw-r--r-- 10,082 bytes parent folder | download
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*     -*-C++-*- -*-coding: utf-8-unix;-*-
  Classified Ads is Copyright (c) Antti Järvinen 2013-2018.

  This file is part of Classified Ads.

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

  Classified Ads 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with Classified Ads; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef M_CONTROLLER_H
#define M_CONTROLLER_H
#include <QObject>
#include "util/hash.h" // Hash
#include "datamodel/netrequestexecutor.h"
#include "datamodel/cadbrecord.h" // for CaDbRecord::SearchTerms

#define CLASSIFIED_ADS_VERSION "0.13"

class Node ;
class Model ;
class NetworkListener ;
class NetworkConnectorEngine ;
class NetworkRequestExecutor;
class BinaryFile ;
class VoiceCallEngine ;
class MVoiceCallEngine ;
class TclWrapper ;
class QWidget ;

/**
 * @brief Pure-virtual interface class for controller.
 * This is spammed
 * across parties needing access to application controller.
 * Reason for this interface is that for testing purposes we can
 * replace real controller with a dummy mock-up
 */
class MController : public QObject {
    Q_OBJECT

public:
    /**
     * Enumeration for different errors that may occur within this
     * app. Class controller is supposed to handle these and may
     * be signaled an error
     */
    enum CAErrorSituation {
        OwnCertNotFound, /**< Does not have own cert and can't generate */
        DataBaseNotMountable, /**< corrupt database or permission? */
        BadPassword, /**< Could not open encryption keys with given pwd */
        DbTransactionError, /**< something went foul with db */
        ContentEncryptionError, /**< something went foul with content encryption interface */
        FileOperationError, /**< Error related to binary files */
        TCLEvalError /**< Error related to TCL evaluation */
    } ;

    /**
     * Enumeration for different user-interface actions that
     * controller tries to route
     */
    enum CAUserInterfaceRequest {
        ViewProfileDetails, /**< User wants to view details of profile */
        ViewCa, /**< User wants to view classified ad */
        ViewProfileComment, /**< User wants to view profile comment */
        DisplayProgressDialog, /**< puts wait dialog on screen */
        VoiceCallToNode /**< User wants voice call to remote node */
    } ;

    /**
     * Method that starts actions regarding content fetch from
     * network
     * @param aReq specifies the content,at least iRequestType and
     *             iRequestedItem need to be there
     * @param aIsBackgroundDl is true if the retrieval may be
     *        queued into background as a low-priority item
     * @param aTypeOfExpectedObject What kind of object is expected, 
     *        possible values include ClassifiedAd, BinaryBlob and UserProfile
     *        from @ref ProtocolItemType. 
     */
    virtual void startRetrievingContent(NetworkRequestExecutor::NetworkRequestQueueItem aReq,
                                        bool aIsBackgroundDl,
                                        ProtocolItemType aTypeOfExpectedObject ) = 0 ;
    /**
     * Variant of "start fetch" method that starts fetch of db records.
     * @param aSearchTerms Database query that fetched record should
     *        satisfy
     */
    virtual void startRetrievingContent( CaDbRecord::SearchTerms aSearchTerms ) = 0 ;

    /**
     * Method for requesting different things to take place in UI.
     * controller mostly routes these to FrontWidget but other actions
     * may be in order too..
     * @param aRequest users orders
     * @param aHashConcerned possible hash parameter ; can be
     *        null hash if action is not about specific hash
     * @param aFetchFromNode possible node hash parameter ; if
     *        concerning item is not found from local storage,
     *        try to fetch it from given node ; is KNullHash,
     *        then just do fetch using normal algorithm.
     * @param aAdditionalInformation possible explanation or other info
     * @return none
     */
    virtual void userInterfaceAction ( CAUserInterfaceRequest aRequest,
                                       const Hash& aHashConcerned = KNullHash,
                                       const Hash& aFetchFromNode = KNullHash,
                                       const QString* aAdditionalInformation = NULL ) = 0 ;

    virtual void hideUI() = 0 ;
    /**
     * method for showing UI
     */
    virtual void showUI() = 0 ;
    /**
     * method selecting user profile in use.
     */
    virtual void setProfileInUse(const Hash& aProfileHash) = 0 ;
    /**
     * method getting user profile in use.
     */
    virtual const Hash& profileInUse() = 0 ;
    /**
     * method for setting passwd used to open private content encryption
     * rsa key. this password is stored in controller
     * and is then used by content-open/sign-operations when crypto lib
     * asks for password.
     */
    virtual void setContentKeyPasswd(QString aPasswd) = 0 ;
    /**
     * method for getting passwd of private content keys previously set, see method
     * @ref Controller::setContentKeyPasswd
     */
    virtual QString contentKeyPasswd()  const = 0;

public slots:
    virtual void exitApp() = 0 ; /**< quitting */
    virtual void displayAboutBox() = 0  ; /**< bragging */
    virtual void displayFront() = 0 ; /**< this initializes the "normal" display */
    /**
     * Method for handling errors inside application.
     * @param aError Reason for error call, from error enum above
     * @param aExplanation NULL or human-readable description about what went
     *                     wrong.
     */
    virtual void handleError(MController::CAErrorSituation aError,
                             const QString& aExplanation) = 0 ;
    /**
     * Method for node ; this may be changed during startup-phase
     * but not after that
     */
    virtual Node& getNode()  const = 0 ;
    /**
     * method for network listener ; it is parent of all connections,
     * also the outgoing
     */
    virtual NetworkListener *networkListener() const = 0 ;
    /**
     * method for getting datamodel
     */
    virtual Model &model() const = 0 ;
    /**
     * method for storing private data of profile currently in use
     *
     * @param aPublishTrustListToo if set to true, has selected profiles
     *        trust list to be updated profile data and profile published
     *        with the new trust list.
     */
    virtual void storePrivateDataOfSelectedProfile(bool aPublishTrustListToo = false ) = 0 ;
    /**
     * method for restoring private data of profile currently in use.
     * shall be called after new profile is selected in frontwidget.
     */
    virtual void reStorePrivateDataOfSelectedProfile() = 0 ;
    /**
     * method for checking if contact is in contact list
     */
    virtual bool isContactInContactList(const Hash& aFingerPrint) const = 0;
    virtual QString displayableNameForProfile(const Hash& aProfileFingerPrint) const = 0 ;
    virtual void offerDisplayNameForProfile(const Hash& aProfileFingerPrint,
                                            const QString& aDisplayName,
                                            const bool iUpdatePersistenStorage=false) = 0 ;
    /**
     * method that puts dialog or similar on display, about a published file
     */
    virtual void displayFileInfoOnUi(const BinaryFile& aFileMetadata) = 0 ;
    /**
     * Method for getting voice call engine. If there is no engine
     * prior to call, one will be constructed
     * @return engine instance
     */
    virtual VoiceCallEngine* voiceCallEngine() = 0 ;

    /**
     * Method for getting voice call engine interface. If there is no engine
     * prior to call, one will be constructed. The instance is the same
     * that is returned via @ref voiceCallEngine method.
     *
     * @return engine instance, possibly a mock-up for testing purposes
     */
    virtual MVoiceCallEngine* voiceCallEngineInterface() = 0 ;

    /**
     * Method for getting tcl wrapper instance. If there is no instance
     * one will be created
     */
    virtual TclWrapper &tclWrapper() = 0 ;

    /**
     * Method for getting front-widget, to be used as parent of dialogs
     * spawned from non-ui threads
     */
    virtual QWidget *frontWidget() = 0 ;
    /**
     * Method for getting file name. Method displays file selection
     * dialog and returns the selected file.  Idea of this method is 
     * that it may be called from background threads and it will
     * display the dialog in UI thread, then report results back.
     * This is a blocking method that will suspend execution of the
     * calling thread for the duration while user is doing the selection. 
     *
     * @param aSuccess is set to true if operation ends all right. 
     * @param aIsSaveFile if set to true, "file save" dialog is
     *        shown, otherwise "file open" dialog.
     * @param aSuggestedFileName file name (pattern). If given empty,
     *        any file is suggested in dialog, if "*.jpg" is given, then
     *        dialog shall suggest only files with .jpg ending and
     *        if "foobar.txt" is given, then dialog will suggest literal
     *        file name "foobar.txt". 
     * @return file system file name or empty if aSuccess is set to false. 
     */
    virtual QString getFileName(bool& aSuccess,
                                bool aIsSaveFile = false , 
                                QString aSuggestedFileName = QString()) = 0 ;
} ;
#endif