1
/***************************************************************************
2
* DBusAdaptor.cc - D-Bus adaptor allowing other applications to use
5
* Copyright (C) 2008, Matthew J Smith
7
* This file is part of QTM.
8
* QTM is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License (version 2), as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
*****************************************************************************/
24
#include "DBusAdaptor.h"
25
#include "EditingWindow.h"
26
#include "qtm_version.h"
28
#include <QApplication>
30
DBusAdaptor::DBusAdaptor( SysTrayIcon *sti )
31
: QDBusAbstractAdaptor( sti ), _sti( sti )
33
connect( qApp, SIGNAL( aboutToQuit() ), SIGNAL( aboutToQuit() ) );
34
connect( _sti, SIGNAL( quickpostTemplatesUpdated( QStringList ) ),
35
this, SIGNAL( quickpostTemplatesUpdated( QStringList ) ) );
36
connect( _sti, SIGNAL( quickpostTemplateTitlesUpdated( QStringList ) ),
37
this, SIGNAL( quickpostTemplateTitlesUpdated( QStringList ) ) );
40
/** applicationVersion: Returns the version number of the application
42
QString DBusAdaptor::applicationVersion()
44
#if QT_VERSION >= 0x040400
45
return QCoreApplication::applicationVersion();
47
return QString( QTM_VERSION );
51
/** getQuickpostTemplateTitles: Returns a string list of the titles of available quickpost templates
54
QStringList DBusAdaptor::getQuickpostTemplateTitles()
56
return _sti->templateTitles();
59
/** getQuickpostTemplates: Returns a string list of the titles and content of available quickpost templates
60
* in format n.[title].[template] - note that newlines are replaced with \n and closing square brackets
63
QStringList DBusAdaptor::getQuickpostTemplates()
65
return _sti->templates();
68
/** quit - Quits the application
70
Q_NOREPLY void DBusAdaptor::quit()
75
/** saveAll - Saves all open documents
77
Q_NOREPLY void DBusAdaptor::saveAll()
79
Application *qtm = qobject_cast<Application *>( qApp );
83
/** newDocument - Opens a new blank entry
85
Q_NOREPLY void DBusAdaptor::newDocument()
87
EditingWindow *c = new EditingWindow;
91
#if QT_VERSION >= 0x040300
92
QApplication::alert( c );
96
/** newDocumentWithTitleAndText - Opens a new entry
97
* title - The title of the new document
98
* text - The content of the new document
100
void DBusAdaptor::newDocumentWithTitleAndText( QString title, QString text )
102
EditingWindow *c = new EditingWindow( text );
104
c->setPostTitle( title );
108
#if QT_VERSION >= 0x040300
109
QApplication::alert( c );
113
/** quickpost - Does a quickpost. The web location of the quickposted document is the first argument
114
* and the content is the second.
115
* Note that if the web location is associated with a particular template, that template will be
118
void DBusAdaptor::quickpost( QString url, QString content )
120
_sti->quickpostFromDBus( url, content );
123
/** open - Opens a saved entry from disk
124
* Returns true if successful and false if unsuccessful.
126
bool DBusAdaptor::open( QString path )
130
if( !path.isEmpty() ) {
131
EditingWindow *e = new EditingWindow;
132
rv = e->load( path, true );
137
#if QT_VERSION >= 0x040300
138
QApplication::alert( e );