~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/akonadiconsole/rawsocketconsole.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2009 Volker Krause <vkrause@kde.org>
 
3
 
 
4
    This library is free software; you can redistribute it and/or modify it
 
5
    under the terms of the GNU Library General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or (at your
 
7
    option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful, but WITHOUT
 
10
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
12
    License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to the
 
16
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "rawsocketconsole.h"
 
21
 
 
22
#include <akonadi/private/xdgbasedirs_p.h>
 
23
 
 
24
#include <KDebug>
 
25
#include <KGlobalSettings>
 
26
#include <KIcon>
 
27
 
 
28
#include <QFile>
 
29
#include <QLocalSocket>
 
30
#include <QSettings>
 
31
 
 
32
using namespace Akonadi;
 
33
 
 
34
RawSocketConsole::RawSocketConsole(QWidget* parent) :
 
35
  QWidget( parent ),
 
36
  mSocket( new QLocalSocket( this ) )
 
37
{
 
38
  ui.setupUi( this );
 
39
  ui.execButton->setIcon( KIcon( "application-x-executable" ) );
 
40
  connect( ui.execButton, SIGNAL(clicked()), SLOT(execClicked()) );
 
41
  connect( ui.commandEdit, SIGNAL(returnPressed()), SLOT(execClicked()) );
 
42
  connect( ui.connectButton, SIGNAL(clicked()), SLOT(connectClicked()) );
 
43
  ui.protocolView->setFont( KGlobalSettings::fixedFont() );
 
44
 
 
45
  connect( mSocket, SIGNAL(readyRead()), SLOT(dataReceived()) );
 
46
  connect( mSocket, SIGNAL(connected()), SLOT(connected()) );
 
47
  connect( mSocket, SIGNAL(disconnected()), SLOT(disconnected()) );
 
48
 
 
49
  disconnected();
 
50
  connectClicked();
 
51
}
 
52
 
 
53
void RawSocketConsole::execClicked()
 
54
{
 
55
  const QString command = ui.commandEdit->text().trimmed() + '\n';
 
56
  if ( command.isEmpty() )
 
57
    return;
 
58
  mSocket->write( command.toUtf8() );
 
59
  ui.commandEdit->clear();
 
60
  ui.protocolView->append( "<font color=\"red\">" + command + "</font>" );
 
61
}
 
62
 
 
63
void RawSocketConsole::dataReceived()
 
64
{
 
65
  while ( mSocket->canReadLine() ) {
 
66
    const QString line = QString::fromUtf8( mSocket->readLine() );
 
67
    ui.protocolView->append( "<font color=\"blue\">" + line + "</font>" );
 
68
  }
 
69
}
 
70
 
 
71
void RawSocketConsole::connected()
 
72
{
 
73
  ui.connectButton->setChecked( true );
 
74
  ui.connectButton->setText( i18n( "Disconnect" ) );
 
75
  ui.execButton->setEnabled( true );
 
76
  ui.commandEdit->setEnabled( true );
 
77
}
 
78
 
 
79
void RawSocketConsole::disconnected()
 
80
{
 
81
  ui.connectButton->setChecked( false );
 
82
  ui.connectButton->setText( i18n( "Connect" ) );
 
83
  ui.execButton->setEnabled( false );
 
84
  ui.commandEdit->setEnabled( false );
 
85
}
 
86
 
 
87
void RawSocketConsole::connectClicked()
 
88
{
 
89
  if ( mSocket->state() == QLocalSocket::ConnectedState ) {
 
90
    mSocket->close();
 
91
  } else {
 
92
    const QString connectionConfigFile = XdgBaseDirs::akonadiConnectionConfigFile();
 
93
    if ( !QFile::exists( connectionConfigFile ) ) {
 
94
      kWarning( 5250 ) << "Akonadi Client Session: connection config file '"
 
95
      << "akonadi/akonadiconnectionrc can not be found in '"
 
96
      << XdgBaseDirs::homePath( "config" ) << "' nor in any of "
 
97
      << XdgBaseDirs::systemPathList( "config" );
 
98
    }
 
99
    QSettings conSettings( connectionConfigFile, QSettings::IniFormat );
 
100
#ifdef Q_OS_WIN  //krazy:exclude=cpp
 
101
    const QString namedPipe = conSettings.value( QLatin1String( "Data/NamedPipe" ), QLatin1String( "Akonadi" ) ).toString();
 
102
    mSocket->connectToServer( namedPipe );
 
103
#else
 
104
    const QString defaultSocketDir = XdgBaseDirs::saveDir( "data", QLatin1String( "akonadi" ) );
 
105
    const QString path = conSettings.value( QLatin1String( "Data/UnixPath" ), defaultSocketDir + QLatin1String( "/akonadiserver.socket" ) ).toString();
 
106
    mSocket->connectToServer( path );
 
107
#endif
 
108
  }
 
109
}
 
110
 
 
111
#include "rawsocketconsole.moc"