File indexing completed on 2025-01-12 04:20:11

0001 /*
0002     SnoreNotify is a Notification Framework based on Qt
0003     Copyright (C) 2013-2015  Hannah von Reth <vonreth@kde.org>
0004 
0005     SnoreNotify is free software: you can redistribute it and/or modify
0006     it under the terms of the GNU Lesser General Public License as published by
0007     the Free Software Foundation, either version 3 of the License, or
0008     (at your option) any later version.
0009 
0010     SnoreNotify 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 Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public License
0016     along with SnoreNotify.  If not, see <http://www.gnu.org/licenses/>.
0017 */
0018 
0019 #include "fredesktopnotification.h"
0020 
0021 #include <QDBusMetaType>
0022 #include <QImage>
0023 
0024 int FreedesktopImageHint::imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
0025 
0026 FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
0027 {
0028     QImage image(img.convertToFormat(QImage::Format_ARGB32).rgbSwapped());
0029     imageData = QByteArray((char *)image.bits(), image.byteCount());
0030     width = image.width();
0031     height = image.height();
0032     rowstride = image.bytesPerLine();
0033     hasAlpha = image.hasAlphaChannel();
0034     channels = hasAlpha ? 4 : 3;
0035     bitsPerSample = image.depth() / channels;
0036 
0037 }
0038 
0039 QImage FreedesktopImageHint::toQImage() const
0040 {
0041     return QImage((uchar *)imageData.data(), width, height, QImage::Format_ARGB32).rgbSwapped();
0042 }
0043 
0044 QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i)
0045 {
0046     a.beginStructure();
0047     a << i.width <<
0048       i.height <<
0049       i.rowstride <<
0050       i.hasAlpha <<
0051       i.bitsPerSample <<
0052       i.channels <<
0053       i.imageData;
0054     a.endStructure();
0055     return a;
0056 }
0057 
0058 const QDBusArgument &operator >>(const QDBusArgument &a,  FreedesktopImageHint &i)
0059 {
0060     a.beginStructure();
0061     a >> i.width >>
0062       i.height >>
0063       i.rowstride >>
0064       i.hasAlpha >>
0065       i.bitsPerSample >>
0066       i.channels >>
0067       i.imageData;
0068     a.endStructure();
0069     return a;
0070 }