File indexing completed on 2024-04-28 05:01:53

0001 /*
0002    SPDX-FileCopyrightText: 2017-2023 Montel Laurent <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "loadroomcache.h"
0008 
0009 #include <KUrlRequester>
0010 #include <QApplication>
0011 #include <QJsonDocument>
0012 #include <QLabel>
0013 #include <QTextEdit>
0014 #include <QVBoxLayout>
0015 
0016 LoadRoomCache::LoadRoomCache(QWidget *parent)
0017     : QWidget(parent)
0018     , mCacheTextEdit(new QTextEdit(this))
0019     , mRequester(new KUrlRequester(this))
0020 {
0021     auto mainLayout = new QVBoxLayout(this);
0022     mCacheTextEdit->setReadOnly(true);
0023     mainLayout->addWidget(mCacheTextEdit);
0024 
0025     auto hbox = new QHBoxLayout;
0026     mainLayout->addLayout(hbox);
0027     hbox->setContentsMargins({});
0028 
0029     auto lab = new QLabel(QStringLiteral("Select cache file:"), this);
0030     hbox->addWidget(lab);
0031 
0032     hbox->addWidget(mRequester);
0033     mRequester->setMode(KFile::File);
0034 
0035     auto openButton = new QPushButton(QStringLiteral("Open"));
0036     hbox->addWidget(openButton);
0037     connect(openButton, &QPushButton::clicked, this, &LoadRoomCache::slotOpenFile);
0038 }
0039 
0040 void LoadRoomCache::slotOpenFile()
0041 {
0042     mCacheTextEdit->clear();
0043 #if 0 // TODO
0044     if (mRequester->url().isValid() && mRequester->url().isLocalFile()) {
0045         QFile f;
0046         f.setFileName(mRequester->url().path());
0047         if (f.open(QIODevice::ReadOnly)) {
0048             QDataStream in(&f);
0049             while (!f.atEnd()) {
0050                 char *byteArray;
0051                 quint32 length;
0052                 in.readBytes(byteArray, length);
0053                 const QByteArray arr = QByteArray::fromRawData(byteArray, length);
0054                 const QByteArray expandJSon = QJsonDocument::fromBinaryData(arr).toJson();
0055                 mCacheTextEdit->append(QString::fromUtf8(expandJSon));
0056             }
0057         }
0058     }
0059 #endif
0060 }
0061 
0062 int main(int argc, char *argv[])
0063 {
0064     QApplication app(argc, argv);
0065     LoadRoomCache w;
0066     w.show();
0067     return app.exec();
0068 }
0069 
0070 #include "moc_loadroomcache.cpp"