Classified ads
controller.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013-2017.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
53 #ifndef CONTROLLER_H
54 #define CONTROLLER_H
55 #include <QtGui>
56 #include <QBoxLayout>
57 #include <QUrl>
58 #include "mcontroller.h"
59 #include "net/protocol.h" // for ProtocolItemType
61 
62 class FrontWidget ;
63 class PublishingEngine ;
64 class RetrievalEngine ;
66 class QMainWindow ;
67 class QMenu ;
68 class VoiceCallEngine ;
69 class QSharedMemory ;
70 #ifdef WIN32
71 class QLocalServer ;
72 #endif
73 class QFileDialog ;
74 
83 class Controller : public MController {
84  Q_OBJECT
85 
86 public:
87 
91  Controller(QApplication& app) ;
95  ~Controller() ;
96 
105  bool init() ;
106 
116  bool aIsBackgroundDl,
117  ProtocolItemType aTypeOfExpectedObject) ;
123  virtual void startRetrievingContent( CaDbRecord::SearchTerms aSearchTerms ) ;
140  virtual void userInterfaceAction ( CAUserInterfaceRequest aRequest,
141  const Hash& aHashConcerned = KNullHash,
142  const Hash& aFetchFromNode = KNullHash,
143  const QString* aAdditionalInformation = NULL) ;
147  virtual void hideUI() ;
151  virtual void showUI() ;
155  virtual void setProfileInUse(const Hash& aProfileHash) ;
159  virtual const Hash& profileInUse() ;
166  virtual void setContentKeyPasswd(QString aPasswd) ;
171  virtual QString contentKeyPasswd() const ;
172 
173 public: // methods
178  virtual Node& getNode() const ;
183  virtual NetworkListener *networkListener() const ;
187  virtual Model &model() const ;
198  void addObjectToOpen(QUrl aClassifiedAdsObject) ;
207 signals:
208  void userProfileSelected(const Hash& aProfile) ;
210  void waitDialogToBeDismissed() ;
211  void startGettingFileName(QString aSuggestedFileName,bool aIsSaveFile) ;
212 public slots:
213  virtual void exitApp() ;
214  virtual void displayAboutBox() ;
215  virtual void displayFront() ;
216  virtual void changeProfilePasswd() ;
217  virtual void createProfile() ;
218  virtual void deleteProfile() ;
219  virtual void selectProfile() ;
220  virtual void displaySettings() ;
221  virtual void displayStatus() ;
222  virtual void displaySearch() ;
224  /* tcl-related UI slots */
225  virtual void displayTclProgs() ;
226  virtual void displayTclConsole() ;
234  virtual void handleError(MController::CAErrorSituation aError,
235  const QString& aExplanation) ;
243  void notifyOfContentReceived(const Hash& aHashOfContent,
244  const ProtocolItemType aTypeOfReceivedContent );
255  void notifyOfContentReceived(const Hash& aHashOfContent,
256  const Hash& aHashOfClassification,
257  const ProtocolItemType aTypeOfReceivedContent );
266  void notifyOfContentNotReceived(const Hash& aHashOfContent,
267  const ProtocolItemType aTypeOfNotReceivdContent );
268 
280  virtual void storePrivateDataOfSelectedProfile(bool aPublishTrustListToo = false) ;
285  virtual void reStorePrivateDataOfSelectedProfile() ;
286 
291  virtual bool isContactInContactList(const Hash& aFingerPrint) const ;
298  virtual QString displayableNameForProfile(const Hash& aProfileFingerPrint) const ;
304  virtual void offerDisplayNameForProfile(const Hash& aProfileFingerPrint,
305  const QString& aDisplayName,
306  const bool iUpdatePersistenStorage=false) ;
310  virtual void displayFileInfoOnUi(const BinaryFile& aFileMetadata) ;
316  virtual VoiceCallEngine* voiceCallEngine() ;
328  virtual TclWrapper &tclWrapper() ;
329 
334  virtual QWidget *frontWidget() ;
352  void sendProfileUpdateQuery(const Hash& aProfileFingerPrint,
353  const Hash& aProfileNodeFingerPrint = KNullHash ) ;
354 #ifdef WIN32
355  void newInstanceConnected() ;
356 #endif
357 
375  virtual QString getFileName(bool& aSuccess,
376  bool aIsSaveFile = false ,
377  QString aSuggestedFileName = QString()) ;
378 private:
379  void createMenus();
380  int createPidFile();
381  void deletePidFile();
386  bool createSharedMemSegment(QString& aSegmentName);
387 private slots:
388  void checkForObjectToOpen(const Hash& aIgnored) ;
393  void getFileNameSlot(QString aSuggestedFileName,bool aIsSaveFile) ;
394 private:
395  QMainWindow* iWin ;
397  QApplication& iApp ;
398  QBoxLayout* iLayout ;
399  QMenu *iFileMenu;
400  QAction *iExitAct;
401  QAction *iAboutAct;
402  QAction *iPwdChangeAct;
409  QMenu *iTclMenu;
410  QAction *iTclLibraryAct;
411  QAction *iTclConsoleAct;
416  QString iContentKeyPasswd ;
448  QMap<Hash,QString> iHashDisplaynameMapping ;
465  QSharedMemory* iSharedMemory ;
466 #ifdef WIN32
467  QLocalServer* iLocalServer ;
468 #endif
473  QFileDialog* iGetFileNameDialog ;
476  QSemaphore iGetFileNameSemaphore ;
480 } ;
481 #endif
482 
virtual void selectProfile()
virtual void startRetrievingContent(NetworkRequestExecutor::NetworkRequestQueueItem aReq, bool aIsBackgroundDl, ProtocolItemType aTypeOfExpectedObject)
Definition: FrontWidget.h:43
bool iGetFileNameSuccess
Definition: controller.h:479
virtual void showUI()
Controller(QApplication &app)
QAction * iProfileCreateAct
Definition: controller.h:404
Class for keeping app state.
Definition: controller.h:83
virtual void displayTclConsole()
virtual void createProfile()
QString iGetFileNameResult
Definition: controller.h:471
Pure-virtual interface for voice call engine.
Definition: mvoicecallengine.h:33
virtual void displayFront()
Node is a peer in network.
Definition: node.h:40
QSharedMemory * iSharedMemory
Definition: controller.h:465
FrontWidget * iCurrentWidget
Definition: controller.h:396
NetworkListener * iListener
Definition: controller.h:414
void addObjectToOpen(QUrl aClassifiedAdsObject)
int createPidFile()
QMainWindow * iWin
Definition: controller.h:395
QApplication & iApp
Definition: controller.h:397
Hash iHashOfObjectBeingWaitedFor
Definition: controller.h:431
virtual void offerDisplayNameForProfile(const Hash &aProfileFingerPrint, const QString &aDisplayName, const bool iUpdatePersistenStorage=false)
void notifyOfContentNotReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfNotReceivdContent)
Network-connection logic relating fetching items from DHT.
Definition: retrievalengine.h:40
virtual void displaySearch()
QAction * iTclConsoleAct
Definition: controller.h:411
bool iInsideDestructor
Definition: controller.h:456
virtual void displayFileInfoOnUi(const BinaryFile &aFileMetadata)
virtual void handleError(MController::CAErrorSituation aError, const QString &aExplanation)
CAUserInterfaceRequest
Definition: mcontroller.h:71
virtual bool isContactInContactList(const Hash &aFingerPrint) const
QFileDialog * iGetFileNameDialog
Definition: controller.h:473
QAction * iExitAct
Definition: controller.h:400
QSemaphore iGetFileNameSemaphore
Definition: controller.h:476
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:57
virtual void displaySettings()
QMenu * iTclMenu
Definition: controller.h:409
bool createSharedMemSegment(QString &aSegmentName)
QAction * iAboutAct
Definition: controller.h:401
Hash iNodeForCommentBeingWaitedFor
Definition: controller.h:444
void checkForObjectToOpen(const Hash &aIgnored)
virtual Model & model() const
ProtocolItemType
Definition: protocol.h:157
Carrier-class for binary blob.
Definition: binaryfile.h:37
Hash iProfileHash
Definition: controller.h:417
QString iContentKeyPasswd
Definition: controller.h:416
void userProfileSelected(const Hash &aProfile)
virtual void exitApp()
virtual void setContentKeyPasswd(QString aPasswd)
QAction * iDisplaySettingsAct
Definition: controller.h:406
virtual const Hash & profileInUse()
VoiceCallEngine * iVoiceCallEngine
Definition: controller.h:452
class for listening to incoming network connections.
Definition: networklistener.h:42
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
void checkForSharedMemoryContents()
Network-connection logic relating fetching db records from DHT.
Definition: dbretrievalengine.h:50
virtual QString contentKeyPasswd() const
QAction * iProfileSelectAct
Definition: controller.h:405
QMenu * iFileMenu
Definition: controller.h:399
void deletePidFile()
Hash KNullHash
virtual QString getFileName(bool &aSuccess, bool aIsSaveFile=false, QString aSuggestedFileName=QString())
QAction * iProfileDeleteAct
Definition: controller.h:403
virtual void storePrivateDataOfSelectedProfile(bool aPublishTrustListToo=false)
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
virtual void userInterfaceAction(CAUserInterfaceRequest aRequest, const Hash &aHashConcerned=KNullHash, const Hash &aFetchFromNode=KNullHash, const QString *aAdditionalInformation=NULL)
void sendProfileUpdateQuery(const Hash &aProfileFingerPrint, const Hash &aProfileNodeFingerPrint=KNullHash)
virtual VoiceCallEngine * voiceCallEngine()
virtual void hideUI()
QBoxLayout * iLayout
Definition: controller.h:398
Node * iNode
Definition: controller.h:412
void startGettingFileName(QString aSuggestedFileName, bool aIsSaveFile)
Class that will initiate 1 or more network connections.
Definition: networkconnectorengine.h:45
virtual void displayAboutBox()
virtual void deleteProfile()
DbRecordRetrievalEngine * iDbRetrievalEngine
Definition: controller.h:420
virtual void displayTclProgs()
virtual MVoiceCallEngine * voiceCallEngineInterface()
virtual Node & getNode() const
virtual QWidget * frontWidget()
QAction * iDisplaySearchAct
Definition: controller.h:408
virtual NetworkListener * networkListener() const
Hash iHashOfProfileCommentBeingWaitedFor
Definition: controller.h:439
void waitDialogToBeDismissed()
Work queue item.
Definition: netrequestexecutor.h:60
RetrievalEngine * iRetrievalEngine
Definition: controller.h:419
QUrl iObjectToOpen
Definition: controller.h:460
bool init()
virtual void changeProfilePasswd()
virtual void displayStatus()
QAction * iDisplayStatusAct
Definition: controller.h:407
Class providing TCL interpreter services.
Definition: tclWrapper.h:652
Network-connection logic relating content publish demands.
Definition: publishingengine.h:41
PublishingEngine * iPubEngine
Definition: controller.h:418
void notifyOfContentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivedContent)
virtual void setProfileInUse(const Hash &aProfileHash)
void getFileNameSlot(QString aSuggestedFileName, bool aIsSaveFile)
virtual TclWrapper & tclWrapper()
TclWrapper * iTclWrapper
Definition: controller.h:469
QAction * iTclLibraryAct
Definition: controller.h:410
Network-related logic for handling voice channel between nodes.
Definition: voicecallengine.h:54
QMap< Hash, QString > iHashDisplaynameMapping
Definition: controller.h:448
QAction * iPwdChangeAct
Definition: controller.h:402
virtual void reStorePrivateDataOfSelectedProfile()
virtual QString displayableNameForProfile(const Hash &aProfileFingerPrint) const
NetworkConnectorEngine * iNetEngine
Definition: controller.h:415
Definition: cadbrecord.h:40
Model * iModel
Definition: controller.h:413
void createMenus()
ProtocolItemType iTypeOfObjectBeingWaitedFor
Definition: controller.h:427