File indexing completed on 2024-04-28 16:24:35
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2019 Dag Andersen <danders@get2net.dk> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "kptloadsharedprojectsdialog.h" 0021 0022 #include "kptproject.h" 0023 0024 #include <QTreeView> 0025 #include <QStandardItemModel> 0026 #include <QStringList> 0027 #include <QList> 0028 #include <QUrl> 0029 #include <QFileInfo> 0030 #include <QDir> 0031 0032 #include <KLocalizedString> 0033 0034 using namespace KPlato; 0035 0036 LoadSharedProjectsDialog::LoadSharedProjectsDialog(Project &project, const QUrl &own, QWidget *parent) 0037 : KoDialog(parent) 0038 , m_view(new QTreeView(this)) 0039 { 0040 setCaption(xi18nc("@title:window", "Load Resource Assignments")); 0041 setButtons(KoDialog::Ok | KoDialog::Cancel); 0042 setDefaultButton(Ok); 0043 showButtonSeparator(true); 0044 0045 setMainWidget(m_view); 0046 0047 QList<QUrl> skip; 0048 skip << own << project.sharedProjectsUrl(); 0049 0050 QFileInfo fi(project.sharedProjectsUrl().path()); 0051 QDir dir = fi.dir(); 0052 QList<QUrl> paths; 0053 foreach(const QString &f, dir.entryList(QStringList()<<"*.plan")) { 0054 QString path = dir.canonicalPath(); 0055 if (path.isEmpty()) { 0056 continue; 0057 } 0058 path += '/' + f; 0059 QUrl url = QUrl::fromLocalFile(path); 0060 if (!skip.contains(url)) { 0061 paths << url; 0062 } 0063 } 0064 QStandardItemModel *m = new QStandardItemModel(m_view); 0065 for (int i = 0; i < paths.count(); ++i) { 0066 QStandardItem *item = new QStandardItem(); 0067 item->setData(paths.at(i).fileName(), Qt::DisplayRole); 0068 item->setData(paths.at(i), Qt::UserRole); 0069 item->setData(paths.at(i).toDisplayString(), Qt::ToolTipRole); 0070 item->setCheckable(true); 0071 item->setCheckState(Qt::Checked); 0072 m->appendRow(item); 0073 } 0074 m_view->setModel(m); 0075 m_view->setHeaderHidden(true); 0076 m_view->setRootIsDecorated(false); 0077 } 0078 0079 QList<QUrl> LoadSharedProjectsDialog::urls() const 0080 { 0081 QList<QUrl> urls; 0082 QStandardItemModel *m = qobject_cast<QStandardItemModel*>(m_view->model()); 0083 if (m) { 0084 for (int i = 0; i < m->rowCount(); ++i) { 0085 QStandardItem *item = m->item(i); 0086 if (item->checkState()) { 0087 urls << item->data(Qt::UserRole).toUrl(); 0088 } 0089 } 0090 } 0091 return urls; 0092 }