don't use QObject for Q_Metatype

This commit is contained in:
Patrick von Reth 2010-08-09 00:47:18 +02:00
parent ce83740e82
commit 801fab9dac
5 changed files with 37 additions and 44 deletions

View File

@ -47,7 +47,7 @@ Notification::Notification ( Notification_Frontend *source, const QString &appli
_id ( id ),
_timeout ( timeout ),
_source ( source ),
_app ( application ),
_application ( application ),
_alert ( alert ),
_title ( title ),
_text ( text ),
@ -101,7 +101,7 @@ const Notification_Frontend *Notification::source() const
const QString &Notification::application() const
{
return _app;
return _application;
}
const QString &Notification::title() const

View File

@ -66,7 +66,7 @@ private:
int _timeout;
actions _actionInvoked;
class Notification_Frontend *_source;
QString _app;
QString _application;
QString _alert;
QString _title;
QString _text;

View File

@ -21,51 +21,49 @@
#include <iostream>
FreedesktopNotification::FreedesktopNotification(QObject* parent)
FreedesktopNotification::FreedesktopNotification()
{
setParent(parent);
registerTypes();
}
FreedesktopNotification::FreedesktopNotification(QSharedPointer< Notification > noti, QObject* parent):
FreedesktopNotification::FreedesktopNotification(QSharedPointer< Notification > noti):
notification(noti)
{
setParent(parent);
registerTypes();
}
void FreedesktopNotification::registerTypes() {
qDBusRegisterMetaType<FreedesktopImageHint*>();
qDBusRegisterMetaType<FreedesktopNotification*>();
qDBusRegisterMetaType<FreedesktopImageHint>();
qDBusRegisterMetaType<FreedesktopNotification>();
}
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification *i) {
Q_ASSERT(!i->notification.isNull());
a<<i->notification->application();
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i) {
Q_ASSERT(!i.notification.isNull());
qDebug()<<i.notification->toString();
a<<i.notification->application();
a<<uint(0);
a<<i->notification->icon();
a<<i->notification->title();
a<<i->notification->text();
a<<i.notification->icon();
a<<i.notification->title();
a<<i.notification->text();
QStringList actions;
actions<<"1"<<" "<<"2"<<" ";
a<<actions;
a.beginMap();
QImage img(i->notification->icon());
QImage img(i.notification->icon());
if (!img.isNull()) {
img=img.scaledToWidth(50,Qt::FastTransformation);
a.beginMapEntry();
a<<"image_data";
FreedesktopImageHint *fh = new FreedesktopImageHint(img);
FreedesktopImageHint fh(img);
a<<fh;
fh->deleteLater();
a.endMapEntry();
}
a.endMap();
a<<i->notification->timeout()*1000;
a<<i.notification->timeout()*1000;
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification *) {
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &) {
//not supported
return a;
}
@ -94,18 +92,16 @@ QImage FreedesktopImageHint::toQImage()const {
return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped();
}
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint *i) {
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
a.beginStructure();
a << i->width<<i->height<<i->rowstride<<i->hasAlpha<<i->bitsPerSample<<i->channels<<i->imageData;
a << i.width<<i.height<<i.rowstride<<i.hasAlpha<<i.bitsPerSample<<i.channels<<i.imageData;
a.endStructure();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint *i) {
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) {
a.beginStructure();
a >> i->width>> i->height>> i->rowstride>> i->hasAlpha>> i->bitsPerSample>> i->channels>> i->imageData;
a >> i.width>> i.height>> i.rowstride>> i.hasAlpha>> i.bitsPerSample>> i.channels>> i.imageData;
a.endStructure();
return a;
}
#include "fredesktopnotification.moc"

View File

@ -16,36 +16,32 @@
#ifndef FreedesktopNotification_H
#define FreedesktopNotification_H
#include <QtDBus>
#include <QPointer>
#include "core/notification.h"
#include <QtDBus>
#include <QMetaType>
class FreedesktopImageHint;
class FreedesktopNotification:public QObject{
Q_OBJECT
class FreedesktopNotification{
public:
static void registerTypes();
public:
FreedesktopNotification(QObject * parent=0);
FreedesktopNotification(QSharedPointer<Notification> noti,QObject * parent=0);
QPointer<FreedesktopImageHint> image;
FreedesktopNotification();
FreedesktopNotification(QSharedPointer<Notification> noti);
QSharedPointer<Notification> notification;
};
Q_DECLARE_METATYPE(FreedesktopNotification*);
Q_DECLARE_METATYPE(FreedesktopNotification);
QDBusArgument &operator<<(QDBusArgument &a,const FreedesktopNotification *i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification *i) ;
QDBusArgument &operator<<(QDBusArgument &a,const FreedesktopNotification &i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &i) ;
class FreedesktopImageHint:public QObject
class FreedesktopImageHint
{
Q_OBJECT
public:
FreedesktopImageHint();
FreedesktopImageHint(const QImage &img);
@ -62,9 +58,10 @@ public:
};
Q_DECLARE_METATYPE(FreedesktopImageHint*);
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint *i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint *i) ;
Q_DECLARE_METATYPE(FreedesktopImageHint);
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ;
#endif // FreedesktopNotification_H

View File

@ -62,7 +62,7 @@ fNotification::fNotification(QSharedPointer< Notification > notification, Freede
uint fNotification::send()
{
Q_ASSERT(!_notification.isNull());
FreedesktopNotification *n = new FreedesktopNotification( _notification );
FreedesktopNotification n ( _notification );
QDBusMessage recive=notificationInterface.call ( "Notify", QVariant::fromValue ( n ) );
uint id=recive.arguments().last().toInt();
selfdistruct = new QTimer(this );