typo found by Andrey Cherepanov
[kdepim.git] / akonadiconsole / rawsocketconsole.cpp
blob62aba2d4664c6a5c67d0b11e92a233d28b6e379f
1 /*
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
17 02110-1301, USA.
20 #include "rawsocketconsole.h"
22 #include <akonadi/private/xdgbasedirs_p.h>
24 #include <KDebug>
25 #include <KGlobalSettings>
26 #include <KIcon>
28 #include <QFile>
29 #include <QLocalSocket>
30 #include <QSettings>
32 using namespace Akonadi;
34 RawSocketConsole::RawSocketConsole(QWidget* parent) :
35 QWidget( parent ),
36 mSocket( new QLocalSocket( this ) )
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() );
45 connect( mSocket, SIGNAL(readyRead()), SLOT(dataReceived()) );
46 connect( mSocket, SIGNAL(connected()), SLOT(connected()) );
47 connect( mSocket, SIGNAL(disconnected()), SLOT(disconnected()) );
49 disconnected();
50 connectClicked();
53 void RawSocketConsole::execClicked()
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>" );
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 ) {
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" );
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
111 #include "rawsocketconsole.moc"