2
Copyright (c) 2009 Volker Krause <vkrause@kde.org>
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.
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.
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
20
#include "rawsocketconsole.h"
22
#include <akonadi/private/xdgbasedirs_p.h>
25
#include <KGlobalSettings>
29
#include <QLocalSocket>
32
using namespace Akonadi;
34
RawSocketConsole::RawSocketConsole(QWidget* parent) :
36
mSocket( new QLocalSocket( 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() );
45
connect( mSocket, SIGNAL(readyRead()), SLOT(dataReceived()) );
46
connect( mSocket, SIGNAL(connected()), SLOT(connected()) );
47
connect( mSocket, SIGNAL(disconnected()), SLOT(disconnected()) );
53
void RawSocketConsole::execClicked()
55
const QString command = ui.commandEdit->text().trimmed() + '\n';
56
if ( command.isEmpty() )
58
mSocket->write( command.toUtf8() );
59
ui.commandEdit->clear();
60
ui.protocolView->append( "<font color=\"red\">" + command + "</font>" );
63
void RawSocketConsole::dataReceived()
65
while ( mSocket->canReadLine() ) {
66
const QString line = QString::fromUtf8( mSocket->readLine() );
67
ui.protocolView->append( "<font color=\"blue\">" + line + "</font>" );
71
void RawSocketConsole::connected()
73
ui.connectButton->setChecked( true );
74
ui.connectButton->setText( i18n( "Disconnect" ) );
75
ui.execButton->setEnabled( true );
76
ui.commandEdit->setEnabled( true );
79
void RawSocketConsole::disconnected()
81
ui.connectButton->setChecked( false );
82
ui.connectButton->setText( i18n( "Connect" ) );
83
ui.execButton->setEnabled( false );
84
ui.commandEdit->setEnabled( false );
87
void RawSocketConsole::connectClicked()
89
if ( mSocket->state() == QLocalSocket::ConnectedState ) {
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" );
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 );
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 );
111
#include "rawsocketconsole.moc"