emailservices/nmclientapi/src/nmapimailboxlisting.cpp
changeset 76 38bf5461e270
parent 48 10eaf342f539
equal deleted inserted replaced
74:6c59112cfd31 76:38bf5461e270
    17 
    17 
    18 #include "nmapiheaders.h"
    18 #include "nmapiheaders.h"
    19 
    19 
    20 namespace EmailClientApi
    20 namespace EmailClientApi
    21 {
    21 {
    22 
       
    23 /*!
    22 /*!
    24    \class Class for creating list of all mailboxes
    23    \class Class for creating list of all mailboxes
    25  */
    24  */
    26 
    25 
    27 /*!
    26 /*!
    31     NmApiMessageTask(parent)
    30     NmApiMessageTask(parent)
    32 {
    31 {
    33     NM_FUNCTION;
    32     NM_FUNCTION;
    34     
    33     
    35     mNmApiMailboxListingPrivate = new NmApiMailboxListingPrivate(this);
    34     mNmApiMailboxListingPrivate = new NmApiMailboxListingPrivate(this);
    36     mNmApiMailboxListingPrivate->mIsRunning = false;
       
    37 }
    35 }
    38 
    36 
    39 /*!
    37 /*!
    40    Destructor of class. It release engine to be safe if manual releasing won't work.
    38    Destructor of class. It release engine to be safe if manual releasing won't work.
    41  */
    39  */
    42 NmApiMailboxListing::~NmApiMailboxListing()
    40 NmApiMailboxListing::~NmApiMailboxListing()
    43 {
    41 {
    44     NM_FUNCTION;
    42     NM_FUNCTION;
    45     
       
    46     if (mNmApiMailboxListingPrivate->mIsRunning) {
       
    47         mNmApiMailboxListingPrivate->releaseEngine();
       
    48     }
       
    49 }
    43 }
    50 
    44 
    51 /*! 
    45 /*! 
    52    \brief Returns results after mailboxesListed signal is received.
    46    \brief Returns results after mailboxesListed signal is received.
    53    
    47    
    56     It also at start clear inputlist of NmApiMailbox.
    50     It also at start clear inputlist of NmApiMailbox.
    57     
    51     
    58     \return Return true if results were avaible
    52     \return Return true if results were avaible
    59     \param mailboxes List of mailboxes to filled. On start is cleared. 
    53     \param mailboxes List of mailboxes to filled. On start is cleared. 
    60  */
    54  */
    61 bool NmApiMailboxListing::getMailboxes(QList<EmailClientApi::NmApiMailbox> &mailboxes)
    55 bool NmApiMailboxListing::getMailboxes(QList<NmApiMailbox> &mailboxes)
    62 {
    56 {
    63     NM_FUNCTION;
    57     NM_FUNCTION;
    64     
    58     return mNmApiMailboxListingPrivate->mailboxes(mailboxes);
    65     mailboxes.clear();
       
    66 
       
    67     bool result = false;
       
    68 
       
    69     if (!mNmApiMailboxListingPrivate->mIsRunning) {
       
    70         result = false;
       
    71     }
       
    72     else
       
    73         if (mNmApiMailboxListingPrivate->mMailboxes.isEmpty()) {
       
    74             result = false;
       
    75         }
       
    76         else {
       
    77             mailboxes = mNmApiMailboxListingPrivate->mMailboxes;
       
    78 
       
    79             mNmApiMailboxListingPrivate->mMailboxes.clear();
       
    80 
       
    81             result = true;
       
    82         }
       
    83     return result;
       
    84 }
    59 }
    85 
    60 
    86 /*!
    61 /*!
    87    \brief Starts gathering mailbox list.
    62    \brief Starts gathering mailbox list.
    88    
    63    
    99    
    74    
   100  */
    75  */
   101 bool NmApiMailboxListing::start()
    76 bool NmApiMailboxListing::start()
   102 {
    77 {
   103     NM_FUNCTION;
    78     NM_FUNCTION;
   104     
    79     qint32 mailboxCount = mNmApiMailboxListingPrivate->listMailboxes();
   105     bool result = false;
    80     QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection,
   106     if (mNmApiMailboxListingPrivate->mIsRunning) {
    81         Q_ARG(qint32, mailboxCount));
   107         result = true;
       
   108     }
       
   109     else
       
   110         if (!mNmApiMailboxListingPrivate->initializeEngine()) {
       
   111             QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
   112                 (qint32) MailboxListingFailed));
       
   113             result = false;
       
   114         }
       
   115         else {
       
   116             qint32 mailboxCount = mNmApiMailboxListingPrivate->grabMailboxes();
       
   117 
    82 
   118             mNmApiMailboxListingPrivate->mIsRunning = true;
    83     return true;
   119 
       
   120             QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
   121                 mailboxCount));
       
   122 
       
   123             result = true;
       
   124         }
       
   125     return result;
       
   126 }
    84 }
   127 
    85 
   128 /*!
    86 /*!
   129    \brief Stop gathering mailbox list.
    87    \brief Stop gathering mailbox list.
   130    
    88    
   134  */
    92  */
   135 void NmApiMailboxListing::cancel()
    93 void NmApiMailboxListing::cancel()
   136 {
    94 {
   137     NM_FUNCTION;
    95     NM_FUNCTION;
   138     
    96     
   139     if (mNmApiMailboxListingPrivate->mIsRunning) {
    97     mNmApiMailboxListingPrivate->cancel();
   140 
    98     emit canceled();
   141         mNmApiMailboxListingPrivate->mIsRunning = false;
       
   142         mNmApiMailboxListingPrivate->releaseEngine();
       
   143         mNmApiMailboxListingPrivate->mMailboxes.clear();
       
   144 
       
   145         QMetaObject::invokeMethod(this, "canceled", Qt::QueuedConnection);
       
   146     }
       
   147 }
    99 }
   148 
   100 
   149 /*!
   101 /*!
   150    \brief Return info if listing is running
   102    \brief Return info if listing is running
   151    
   103    
   152    \return Return true if listing is running
   104    \return Return true if listing is running
   153  */
   105  */
   154 bool NmApiMailboxListing::isRunning() const
   106 bool NmApiMailboxListing::isRunning() const
   155 {
   107 {
   156     NM_FUNCTION;
   108     NM_FUNCTION;
   157     
   109     return mNmApiMailboxListingPrivate->isRunning();
   158     return mNmApiMailboxListingPrivate->mIsRunning;
   110 }
   159 }
   111 }
   160 
   112 
   161 }
       
   162 
   113