File indexing completed on 2021-12-21 13:15:45

0001 /***************************************************************************
0002 *   Copyright 2007 Niko Sams <niko.sams@gmail.com>                        *
0003 *                                                                         *
0004 *   This program is free software; you can redistribute it and/or modify  *
0005 *   it under the terms of the GNU General Public License as published by  *
0006 *   the Free Software Foundation; either version 2 of the License, or     *
0007 *   (at your option) any later version.                                   *
0008 *                                                                         *
0009 ***************************************************************************/
0010 #include "uploadprofileitem.h"
0011 
0012 #include <QUrl>
0013 
0014 #include <kconfiggroup.h>
0015 
0016 #include <interfaces/iproject.h>
0017 
0018 #include "uploadprofilemodel.h"
0019 
0020 UploadProfileItem::UploadProfileItem()
0021 {
0022     setEditable(false);
0023 }
0024 
0025 void UploadProfileItem::setUrl(const QUrl& url)
0026 {
0027     setData(url, UrlRole);
0028 }
0029 void UploadProfileItem::setLocalUrl(const QUrl& url)
0030 {
0031     setData(url, LocalUrlRole);
0032 }
0033 
0034 void UploadProfileItem::setDefault(bool isDefault)
0035 {
0036     setData(isDefault, IsDefaultRole);
0037     if (isDefault) {
0038         setIcon(QIcon::fromTheme("rating"));
0039         UploadProfileModel* m;
0040         if (model() && (m = dynamic_cast<UploadProfileModel*>(model()))) {
0041             for (int i = 0; i < m->rowCount(); i++) {
0042                 UploadProfileItem* item = m->uploadItem(i);
0043                 if (item && item != this) {
0044                     item->setDefault(false);
0045                 }
0046             }
0047         }
0048     } else {
0049         setIcon(QIcon());
0050     }
0051 }
0052 
0053 void UploadProfileItem::setProfileNr(const QString& nr)
0054 {
0055     setData(nr, ProfileNrRole);
0056 }
0057 
0058 QUrl UploadProfileItem::url() const
0059 {
0060     return data(UrlRole).value<QUrl>();
0061 }
0062 QUrl UploadProfileItem::localUrl() const
0063 {
0064     return data(LocalUrlRole).value<QUrl>();
0065 }
0066 
0067 bool UploadProfileItem::isDefault() const
0068 {
0069     return data(IsDefaultRole).toBool();
0070 }
0071 
0072 QString UploadProfileItem::profileNr() const
0073 {
0074     return data(ProfileNrRole).toString();
0075 }
0076 
0077 KConfigGroup UploadProfileItem::profileConfigGroup() const
0078 {
0079     UploadProfileModel* m = nullptr;
0080     if (!profileNr().isEmpty() && model() && (m = dynamic_cast<UploadProfileModel*>(model()))) {
0081         return m->project()->projectConfiguration()->group("Upload").group("Profile"+profileNr());
0082     }
0083     return KConfigGroup();
0084 }
0085 
0086 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on