1 /* This file is part of kdepim.
2 Copyright (C) 2005,2007 Will Stephenson <wstephenson@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 2 of the License,
7 or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
26 #include <QPushButton>
30 #include <KApplication>
31 #include <KCmdLineArgs>
35 #include "networkingservice.h"
36 #include "serviceinterface.h"
38 QString
toString( Solid::Networking::Status st
)
42 case Solid::Networking::Unknown
:
45 case Solid::Networking::Disconnecting
:
46 str
= "Disconnecting";
48 case Solid::Networking::Unconnected
:
51 case Solid::Networking::Connecting
:
54 case Solid::Networking::Connected
:
61 TestService::TestService() : KMainWindow( 0 ),
62 m_service( new OrgKdeSolidNetworkingServiceInterface( "org.kde.kded", "/modules/networkstatus", QDBusConnection::sessionBus(), this ) ),
63 m_status ( Solid::Networking::Unconnected
),
64 m_nextStatus( Solid::Networking::Unconnected
),
65 m_view( new QWidget( this ) )
67 QDBusConnection::sessionBus().registerService( "org.kde.Solid.Networking.TestService" );
70 setCentralWidget( m_view
);
71 connect( ui
.changeCombo
, SIGNAL( activated( int ) ), SLOT( changeComboActivated( int ) ) );
72 connect( ui
.changeButton
, SIGNAL( clicked() ), SLOT( changeButtonClicked() ) );
74 connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(const QString
&, const QString
&, const QString
& ) ), SLOT(serviceOwnerChanged(const QString
&, const QString
&, const QString
& ) ) );
76 ui
.statusLabel
->setText( toString( m_status
) );
78 palette
.setColor( ui
.statusLabel
->backgroundRole(), toQColor( m_status
) );
79 ui
.statusLabel
->setPalette( palette
);
80 setCaption( toString( m_status
) );
85 TestService::~TestService()
90 void TestService::registerService()
92 m_service
->registerNetwork( "test_net", m_status
, "org.kde.Solid.Networking.TestService" );
95 void TestService::serviceOwnerChanged( const QString
& service
,const QString
& oldOwner
, const QString
& newOwner
)
98 if ( !newOwner
.isEmpty() && service
== "org.kde.kded" ) {
99 kDebug() << "KDED restarted, trying to re-register service with it";
104 int TestService::status( const QString
& network
)
107 return (int)m_status
;
110 void TestService::changeComboActivated( int index
)
113 case 0 /*Solid::Networking::Unknown*/:
114 m_nextStatus
= Solid::Networking::Unknown
;
116 case 1 /*Solid::Networking::Unconnected*/:
117 m_nextStatus
= Solid::Networking::Unconnected
;
119 case 2 /*Solid::Networking::Disconnecting*/:
120 m_nextStatus
= Solid::Networking::Disconnecting
;
122 case 3 /*Solid::Networking::Connecting*/:
123 m_nextStatus
= Solid::Networking::Connecting
;
125 case 4 /*Solid::Networking::Connected*/:
126 m_nextStatus
= Solid::Networking::Connected
;
129 kDebug() << "Unrecognised status!";
132 ui
.changeButton
->setEnabled( true );
135 void TestService::changeButtonClicked()
137 ui
.changeButton
->setEnabled( false );
138 m_status
= m_nextStatus
;
139 m_service
->setNetworkStatus( "test_net", ( int )m_status
);
140 ui
.statusLabel
->setText( toString( m_status
) );
142 palette
.setColor( ui
.statusLabel
->backgroundRole(), toQColor( m_status
) );
143 ui
.statusLabel
->setPalette( palette
);
144 setCaption( toString( m_status
) );
147 int TestService::establish( const QString
& network
)
150 m_status
= Solid::Networking::Connecting
;
151 m_service
->setNetworkStatus( "test_net", (int)m_status
);
152 m_nextStatus
= Solid::Networking::Connected
;
153 QTimer::singleShot( 5000, this, SLOT( slotStatusChange() ) );
154 return (int)Solid::Networking::RequestAccepted
;
157 int TestService::shutdown( const QString
& network
)
160 m_status
= Solid::Networking::Disconnecting
;
161 m_service
->setNetworkStatus( "test_net", (int)m_status
);
162 m_nextStatus
= Solid::Networking::Unconnected
;
163 QTimer::singleShot( 5000, this, SLOT( slotStatusChange() ) );
164 return (int)Solid::Networking::RequestAccepted
;
167 void TestService::simulateFailure()
169 m_status
= Solid::Networking::UnconnectedFailed
;
170 m_service
->setNetworkStatus( "test_net", (int)m_status
);
173 void TestService::simulateDisconnect()
175 m_status
= Solid::Networking::UnconnectedDisconnected
;
176 m_service
->setNetworkStatus( "test_net", (int)m_status
);
179 void TestService::slotStatusChange()
181 m_status
= m_nextStatus
;
182 m_service
->setNetworkStatus( "test_net", (int)m_status
);
185 QColor
TestService::toQColor( Solid::Networking::Status st
)
189 case Solid::Networking::Unknown
:
192 case Solid::Networking::Disconnecting
:
193 col
= Qt::darkYellow
;
195 case Solid::Networking::Unconnected
:
198 case Solid::Networking::Connecting
:
201 case Solid::Networking::Connected
:
208 static const char description
[] =
209 I18N_NOOP("Test Service for Network Status kded module");
211 static const char version
[] = "v0.1";
213 int main( int argc
, char** argv
)
215 KAboutData
about("KNetworkStatusTestService", 0, ki18n("knetworkstatustestservice"), version
, ki18n(description
), KAboutData::License_GPL
, ki18n("(C) 2007 Will Stephenson"), KLocalizedString(), 0, "wstephenson@kde.org");
216 about
.addAuthor( ki18n("Will Stephenson"), KLocalizedString(), "wstephenson@kde.org" );
217 KCmdLineArgs::init(argc
, argv
, &about
);
219 KCmdLineOptions options
;
220 KCmdLineArgs::addCmdLineOptions(options
);
223 TestService
* test
= new TestService
;
228 #include "networkingservice.moc"