File indexing completed on 2024-06-30 05:06:32

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "mainwindow.h"
0008 
0009 #include "control.h"
0010 
0011 #include "entitytreeview.h"
0012 #include "fakemonitor.h"
0013 #include "fakeserverdata.h"
0014 #include "fakesession.h"
0015 #include <QTimer>
0016 
0017 using namespace Akonadi;
0018 using namespace std::chrono_literals;
0019 MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
0020     : QMainWindow(parent, flags)
0021 {
0022     auto monitor = new FakeMonitor(this);
0023     auto session = new FakeSession("FS1", FakeSession::EndJobsImmediately, this);
0024     monitor->setSession(session);
0025 
0026     m_model = new EntityTreeModel(monitor, this);
0027     m_serverData = new FakeServerData(m_model, session, monitor, this);
0028 
0029     QList<FakeAkonadiServerCommand *> initialFetchResponse =
0030         FakeJobResponse::interpret(m_serverData,
0031                                    QStringLiteral("- C (inode/directory) 'Col 1' 4"
0032                                                   "- - C (text/directory, message/rfc822) 'Col 2' 3"
0033                                                   // Items just have the mimetype they contain in the payload.
0034                                                   "- - - I text/directory"
0035                                                   "- - - I text/directory 'Item 1'"
0036                                                   "- - - I message/rfc822"
0037                                                   "- - - I message/rfc822"
0038                                                   "- - C (text/directory) 'Col 3' 3"
0039                                                   "- - - C (text/directory) 'Col 4' 2"
0040                                                   "- - - - C (text/directory) 'Col 5' 1" // <-- First collection to be returned
0041                                                   "- - - - - I text/directory"
0042                                                   "- - - - - I text/directory"
0043                                                   "- - - - I text/directory"
0044                                                   "- - - I text/directory"
0045                                                   "- - - I text/directory"
0046                                                   "- - C (message/rfc822) 'Col 6' 3"
0047                                                   "- - - I message/rfc822"
0048                                                   "- - - I message/rfc822"
0049                                                   "- - C (text/directory, message/rfc822) 'Col 7' 3"
0050                                                   "- - - I text/directory"
0051                                                   "- - - I text/directory"
0052                                                   "- - - I message/rfc822"
0053                                                   "- - - I message/rfc822"));
0054     m_serverData->setCommands(initialFetchResponse);
0055 
0056     auto view = new EntityTreeView(this);
0057     view->setModel(m_model);
0058 
0059     view->expandAll();
0060     setCentralWidget(view);
0061 
0062     QTimer::singleShot(5s, this, &MainWindow::moveCollection);
0063 }
0064 
0065 void MainWindow::moveCollection()
0066 {
0067     // Move Col 3 from Col 4 to Col 7
0068     auto moveCommand = new FakeCollectionMovedCommand(QStringLiteral("Col 4"), QStringLiteral("Col 3"), QStringLiteral("Col 7"), m_serverData);
0069 
0070     m_serverData->setCommands(QList<FakeAkonadiServerCommand *>() << moveCommand);
0071     m_serverData->processNotifications();
0072 }
0073 
0074 #include "moc_mainwindow.cpp"