~ubuntu-branches/ubuntu/lucid/qtm/lucid-updates

« back to all changes in this revision

Viewing changes to DBusAdaptor.cc

  • Committer: Bazaar Package Importer
  • Author(s): Patryk Cisek
  • Date: 2009-07-03 15:07:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090703150756-11x75iewoopx1zf6
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 * DBusAdaptor.cc - D-Bus adaptor allowing other applications to use
 
3
 * QTM's features.
 
4
 *
 
5
 * Copyright (C) 2008, Matthew J Smith
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 *
 
21
 *****************************************************************************/
 
22
 
 
23
 
 
24
#include "DBusAdaptor.h"
 
25
#include "EditingWindow.h"
 
26
#include "qtm_version.h"
 
27
 
 
28
#include <QApplication>
 
29
 
 
30
DBusAdaptor::DBusAdaptor( SysTrayIcon *sti )
 
31
  : QDBusAbstractAdaptor( sti ), _sti( sti )
 
32
{
 
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 ) ) );
 
38
}
 
39
 
 
40
/** applicationVersion: Returns the version number of the application
 
41
 */
 
42
QString DBusAdaptor::applicationVersion()
 
43
{
 
44
#if QT_VERSION >= 0x040400
 
45
  return QCoreApplication::applicationVersion();
 
46
#else
 
47
  return QString( QTM_VERSION );
 
48
#endif
 
49
}
 
50
 
 
51
/** getQuickpostTemplateTitles: Returns a string list of the titles of available quickpost templates
 
52
 *  in format n.[title]
 
53
 */
 
54
QStringList DBusAdaptor::getQuickpostTemplateTitles()
 
55
{
 
56
    return _sti->templateTitles();
 
57
}
 
58
 
 
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
 
61
 *  with \]
 
62
 */
 
63
QStringList DBusAdaptor::getQuickpostTemplates()
 
64
{
 
65
  return _sti->templates();
 
66
}
 
67
 
 
68
/** quit - Quits the application
 
69
 */
 
70
Q_NOREPLY void DBusAdaptor::quit()
 
71
{
 
72
  _sti->doQuit();
 
73
}
 
74
 
 
75
/** saveAll - Saves all open documents
 
76
  */
 
77
Q_NOREPLY void DBusAdaptor::saveAll()
 
78
{
 
79
  Application *qtm = qobject_cast<Application *>( qApp );
 
80
  qtm->saveAll();
 
81
}
 
82
 
 
83
/** newDocument - Opens a new blank entry
 
84
 */
 
85
Q_NOREPLY void DBusAdaptor::newDocument()
 
86
{
 
87
  EditingWindow *c = new EditingWindow;
 
88
  c->setSTI( _sti );
 
89
  c->show();
 
90
  c->activateWindow();
 
91
#if QT_VERSION >= 0x040300
 
92
  QApplication::alert( c );
 
93
#endif
 
94
}
 
95
 
 
96
/** newDocumentWithTitleAndText - Opens a new entry
 
97
 *  title - The title of the new document
 
98
 *  text - The content of the new document
 
99
 */
 
100
void DBusAdaptor::newDocumentWithTitleAndText( QString title, QString text )
 
101
{
 
102
  EditingWindow *c = new EditingWindow( text );
 
103
  c->setSTI( _sti );
 
104
  c->setPostTitle( title );
 
105
  c->setPostClean();
 
106
  c->show();
 
107
  c->activateWindow();
 
108
#if QT_VERSION >= 0x040300
 
109
  QApplication::alert( c );
 
110
#endif
 
111
}
 
112
 
 
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
 
116
 *  used.
 
117
 */
 
118
void DBusAdaptor::quickpost( QString url, QString content )
 
119
{
 
120
  _sti->quickpostFromDBus( url, content );
 
121
}
 
122
 
 
123
/** open - Opens a saved entry from disk
 
124
 *  Returns true if successful and false if unsuccessful.
 
125
 */
 
126
bool DBusAdaptor::open( QString path )
 
127
{
 
128
  bool rv = false;
 
129
 
 
130
  if( !path.isEmpty() ) {
 
131
    EditingWindow *e = new EditingWindow;
 
132
    rv = e->load( path, true );
 
133
    if( rv ) {
 
134
      e->setSTI( _sti );
 
135
      e->show();
 
136
      e->activateWindow();
 
137
#if QT_VERSION >= 0x040300
 
138
      QApplication::alert( e );
 
139
#endif
 
140
    }
 
141
    else
 
142
      e->deleteLater();
 
143
  }
 
144
  return rv;
 
145
}