File indexing completed on 2024-04-28 11:50:48
0001 /*************************************************************************** 0002 * Copyright (C) 2012-2016 by Daniel Nicoletti <dantti12@gmail.com> * 0003 * 2022 by Han Young <hanyoung@protonmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; see the file COPYING. If not, write to * 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0018 * Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 #include <KFormat> 0021 0022 #include "CdProfileInterface.h" 0023 #include "Profile.h" 0024 #include "ProfileDescription.h" 0025 #include "ProfileMetaDataModel.h" 0026 #include "ProfileNamedColorsModel.h" 0027 0028 ProfileDescription::ProfileDescription(QObject *parent) 0029 : QObject(parent) 0030 , m_metadataModel(new ProfileMetaDataModel(this)) 0031 , m_namedColorsModel(new ProfileNamedColorsModel(this)) 0032 { 0033 } 0034 0035 void ProfileDescription::setProfile(const QDBusObjectPath &objectPath, bool canRemoveProfile) 0036 { 0037 m_currentProfilePath = objectPath; 0038 m_canRemoveProfile = canRemoveProfile; 0039 0040 CdProfileInterface profileInterface(QStringLiteral("org.freedesktop.ColorManager"), objectPath.path(), QDBusConnection::systemBus()); 0041 if (!profileInterface.isValid()) { 0042 return; 0043 } 0044 0045 const QString filename = profileInterface.filename(); 0046 const bool hasVcgt = profileInterface.hasVcgt(); 0047 const qlonglong created = profileInterface.created(); 0048 0049 Profile profile(filename); 0050 if (profile.loaded()) { 0051 // Set the profile type 0052 m_profileKind = profile.kindString(); 0053 0054 // Set the colorspace 0055 m_profileColorSpace = profile.colorspace(); 0056 0057 // Set the version 0058 m_profileVersion = profile.version(); 0059 0060 // Set the created time 0061 m_profileCreatedTime = QLocale().toString(QDateTime::fromSecsSinceEpoch(created), QLocale::LongFormat); 0062 0063 // Set the license 0064 m_profileLicense = profile.copyright(); 0065 0066 // Set the manufacturer 0067 m_profileManufacturer = profile.manufacturer(); 0068 0069 // Set the Model 0070 m_profileModel = profile.model(); 0071 0072 // Set the Display Correction 0073 m_profileHasDisplayCorrection = hasVcgt; 0074 0075 // Set the file size 0076 m_profileSize = KFormat().formatByteSize(profile.size()); 0077 0078 // Set the file name 0079 QFileInfo fileinfo(profile.filename()); 0080 m_profileName = fileinfo.fileName(); 0081 0082 QString temp; 0083 const uint temperature = profile.temperature(); 0084 if (qAbs(temperature - 5000) < 10) { 0085 temp = QString::fromUtf8("%1K (D50)").arg(QString::number(temperature)); 0086 } else if (qAbs(temperature - 6500) < 10) { 0087 temp = QString::fromUtf8("%1K (D65)").arg(QString::number(temperature)); 0088 } else { 0089 temp = QString::fromUtf8("%1K").arg(QString::number(temperature)); 0090 } 0091 m_profileWhitePoint = temp; 0092 0093 qDebug() << profile.description(); 0094 qDebug() << profile.model(); 0095 qDebug() << profile.manufacturer(); 0096 qDebug() << profile.copyright(); 0097 0098 // Get named colors 0099 m_namedColorsModel->setNamedColors(profile.getNamedColors()); 0100 m_metadataModel->setMetadata(profileInterface.metadata()); 0101 } 0102 qDebug() << profile.filename(); 0103 Q_EMIT dataChanged(); 0104 } 0105 0106 ProfileMetaDataModel *ProfileDescription::metaDataModel() const 0107 { 0108 return m_metadataModel; 0109 } 0110 0111 ProfileNamedColorsModel *ProfileDescription::namedColorsModel() const 0112 { 0113 return m_namedColorsModel; 0114 } 0115 0116 void ProfileDescription::installSystemWide() 0117 { 0118 CdProfileInterface profile(QStringLiteral("org.freedesktop.ColorManager"), m_currentProfilePath.path(), QDBusConnection::systemBus()); 0119 profile.InstallSystemWide(); 0120 } 0121 0122 #include "moc_ProfileDescription.cpp"