File indexing completed on 2024-11-24 04:53:09

0001 /*  Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org>
0002     Certain enhancements (www.xtuple.com/trojita-enhancements)
0003     are copyright © 2010 by OpenMFG LLC, dba xTuple.  All rights reserved.
0004 
0005     Redistribution and use in source and binary forms, with or without
0006     modification, are permitted provided that the following conditions are met:
0007 
0008     - Redistributions of source code must retain the above copyright notice, this
0009     list of conditions and the following disclaimer.
0010     - Redistributions in binary form must reproduce the above copyright notice,
0011     this list of conditions and the following disclaimer in the documentation
0012     and/or other materials provided with the distribution.
0013     - Neither the name of xTuple nor the names of its contributors may be used to
0014     endorse or promote products derived from this software without specific prior
0015     written permission.
0016 
0017     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0020     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
0021     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0022     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0023     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
0024     ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0026     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 
0028 */
0029 
0030 #ifndef TROJITA_IMAP_MAILBOXFINDER_H
0031 #define TROJITA_IMAP_MAILBOXFINDER_H
0032 
0033 #include <QModelIndex>
0034 #include <QSet>
0035 
0036 namespace Imap {
0037 
0038 namespace Mailbox {
0039 
0040 /** @short Find model indexes for mailboxes
0041 
0042 The API of the Model doesn't currently have a way of asking for a QModelIndex for a named mailbox.
0043 This class fills that gap.
0044 
0045 To start, call the addMailbox() method for each mailbox that you want to look up. Then, after
0046 several invocations of the event loop, the IMAP server will be asked for incremental mailbox
0047 listing, nesting as needed. When the mailbox is found, the mailboxFound() slot will fire.
0048 
0049 When there's a problem finding that mailbox, no signal will be emitted. This is related to how the
0050 Model currently works, because the Tasks have no way of informing the user that they failed.
0051 
0052 In addition, the MailboxFinder works purely on MVC layer, so it has no IMAP knowledge besides custom
0053 item roles.
0054 */
0055 class MailboxFinder : public QObject
0056 {
0057     Q_OBJECT
0058 public:
0059     MailboxFinder(QObject *parent, QAbstractItemModel *model);
0060 
0061     /** @short Specify an interest in obtaining an index for this mailbox */
0062     void addMailbox(const QString &mailbox);
0063 
0064 signals:
0065     /** @short Fires when the mapping has been found
0066 
0067     If the mailbox isn't found, no signal is emitted.
0068     */
0069     void mailboxFound(const QString &mailbox, const QModelIndex &index);
0070 
0071 private slots:
0072     /** @short Walk the internal list of names that we're interested in, ask the model for data if needed */
0073     void checkArrivals();
0074 
0075 private:
0076     QAbstractItemModel *m_model;
0077     QSet<QString> m_pending;
0078 };
0079 
0080 }
0081 }
0082 
0083 #endif