File indexing completed on 2024-12-22 04:56:52
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 * 0006 */ 0007 0008 #include "migrationstatuswidget.h" 0009 #include <KLocalizedString> 0010 #include <QAction> 0011 #include <QDialog> 0012 #include <QDialogButtonBox> 0013 #include <QIcon> 0014 #include <QLabel> 0015 #include <QListView> 0016 #include <QToolBar> 0017 #include <QTreeView> 0018 #include <QVBoxLayout> 0019 0020 MigrationStatusWidget::MigrationStatusWidget(MigrationScheduler &scheduler, QWidget *parent) 0021 : QWidget(parent) 0022 , mScheduler(scheduler) 0023 { 0024 auto vboxLayout = new QVBoxLayout(this); 0025 auto toolbar = new QToolBar(QStringLiteral("MigrationControlToolbar"), this); 0026 0027 QAction *start = toolbar->addAction(QStringLiteral("Start")); 0028 start->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start"))); 0029 connect(start, &QAction::triggered, this, &MigrationStatusWidget::startSelected); 0030 0031 QAction *pause = toolbar->addAction(QStringLiteral("Pause")); 0032 pause->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause"))); 0033 connect(pause, &QAction::triggered, this, &MigrationStatusWidget::pauseSelected); 0034 0035 QAction *abort = toolbar->addAction(QStringLiteral("Abort")); 0036 abort->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-stop"))); 0037 connect(abort, &QAction::triggered, this, &MigrationStatusWidget::abortSelected); 0038 0039 vboxLayout->addWidget(toolbar); 0040 auto treeView = new QTreeView(this); 0041 treeView->setModel(&mScheduler.model()); 0042 mSelectionModel = treeView->selectionModel(); 0043 Q_ASSERT(mSelectionModel); 0044 // Not sure why this is required, but otherwise the view doesn't load anything from the model 0045 treeView->update(QModelIndex()); 0046 connect(treeView, &QTreeView::doubleClicked, this, &MigrationStatusWidget::onItemActivated); 0047 0048 vboxLayout->addWidget(treeView); 0049 } 0050 0051 void MigrationStatusWidget::startSelected() 0052 { 0053 const QModelIndexList lst = mSelectionModel->selectedRows(); 0054 for (const QModelIndex &index : lst) { 0055 mScheduler.start(index.data(MigratorModel::IdentifierRole).toString()); 0056 } 0057 } 0058 0059 void MigrationStatusWidget::pauseSelected() 0060 { 0061 const QModelIndexList lst = mSelectionModel->selectedRows(); 0062 for (const QModelIndex &index : lst) { 0063 mScheduler.pause(index.data(MigratorModel::IdentifierRole).toString()); 0064 } 0065 } 0066 0067 void MigrationStatusWidget::abortSelected() 0068 { 0069 const QModelIndexList lst = mSelectionModel->selectedRows(); 0070 for (const QModelIndex &index : lst) { 0071 mScheduler.abort(index.data(MigratorModel::IdentifierRole).toString()); 0072 } 0073 } 0074 0075 void MigrationStatusWidget::onItemActivated(const QModelIndex &index) 0076 { 0077 auto dlg = new QDialog(this); 0078 auto topLayout = new QVBoxLayout(dlg); 0079 dlg->setLayout(topLayout); 0080 auto widget = new QWidget(dlg); 0081 topLayout->addWidget(widget); 0082 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, dlg); 0083 connect(buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept); 0084 connect(buttonBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject); 0085 topLayout->addWidget(buttonBox); 0086 0087 auto vboxLayout = new QVBoxLayout; 0088 { 0089 auto listView = new QListView(widget); 0090 listView->setModel(&mScheduler.logModel(index.data(MigratorModel::IdentifierRole).toString())); 0091 listView->setAutoScroll(true); 0092 listView->scrollToBottom(); 0093 vboxLayout->addWidget(listView); 0094 } 0095 { 0096 auto hboxLayout = new QHBoxLayout; 0097 auto label = 0098 new QLabel(QStringLiteral("<a href=\"%1\">%2</a>").arg(index.data(MigratorModel::LogfileRole).toString(), ki18n("Logfile").toString()), widget); 0099 label->setOpenExternalLinks(true); 0100 hboxLayout->addWidget(label); 0101 hboxLayout->addStretch(); 0102 vboxLayout->addLayout(hboxLayout); 0103 } 0104 widget->setLayout(vboxLayout); 0105 0106 dlg->setAttribute(Qt::WA_DeleteOnClose); 0107 dlg->setWindowTitle(i18nc("Title of the window displaying the log of a single migration job.", "Migration Info")); 0108 dlg->resize(600, 300); 0109 dlg->show(); 0110 } 0111 0112 #include "moc_migrationstatuswidget.cpp"