1 /***************************************************************************
2 wpuserinfo.cpp - WinPopup User Info
4 begin : Tue May 06 2003
5 copyright : (C) 2003 by Tais M. Hansen
6 email : tais.hansen@osd.dk
8 Based on code from : (C) 2002-2003 by the Kopete developers
9 email : kopete-devel@kde.org
10 ***************************************************************************
12 ***************************************************************************
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
19 ***************************************************************************/
31 #include "wpuserinfo.h"
32 #include "wpaccount.h"
33 #include "wpcontact.h"
34 #include "ui_wpuserinfowidget.h"
36 WPUserInfo::WPUserInfo( WPContact
*contact
, QWidget
*parent
)
37 : KDialog( parent
), m_contact(contact
),
38 Comment(i18n("N/A")), Workgroup(i18n("N/A")), OS(i18n("N/A")), Software(i18n("N/A"))
40 setButtons( KDialog::Close
);
41 setDefaultButton(KDialog::Close
);
44 setCaption( i18n( "User Info for %1", m_contact
->nickName() ) );
46 QWidget
* w
= new QWidget( this );
47 m_mainWidget
= new Ui::WPUserInfoWidget();
48 m_mainWidget
->setupUi( w
);
51 m_mainWidget
->sComputerName
->setText( m_contact
->contactId() );
53 // m_mainWidget->sComment->setText(i18n("Looking"));
54 // m_mainWidget->sWorkgroup->setText(i18n("Looking"));
55 // m_mainWidget->sOS->setText(i18n("Looking"));
56 // m_mainWidget->sServer->setText(i18n("Looking"));
58 connect( this, SIGNAL( closeClicked() ), this, SLOT( slotCloseClicked() ) );
60 startDetailsProcess(m_contact
->contactId());
63 WPUserInfo::~WPUserInfo()
68 // I decided to do this direct here to avoid "Handstände" with signals and stuff
69 // if we would do this in libwinpopup. GF
70 void WPUserInfo::startDetailsProcess(const QString
&host
)
72 KConfigGroup group
= KGlobal::config()->group("WinPopup");
73 QString theSMBClientPath
= group
.readEntry("SMBClientPath", "/usr/bin/smbclient");
75 detailsProcess
= new QProcess(this);
77 args
<< "-N" << "-g" << "-L" << host
<< "-";
79 connect(detailsProcess
, SIGNAL(finished(int, QProcess::ExitStatus
)), this, SLOT(slotDetailsProcessFinished(int, QProcess::ExitStatus
)));
81 detailsProcess
->setProcessChannelMode(QProcess::MergedChannels
);
82 detailsProcess
->start(theSMBClientPath
, args
);
85 void WPUserInfo::slotDetailsProcessFinished(int, QProcess::ExitStatus
)
87 QByteArray outputData
= detailsProcess
->readAll();
88 QRegExp
info("Domain=\\[(.[^\\]]+)\\]\\sOS=\\[(.[^\\]]+)\\]\\sServer=\\[(.[^\\]]+)\\]"),
89 host("Server\\|" + m_contact
->contactId() + "\\|(.*)");
91 if (!outputData
.isEmpty()) {
92 QString output
= QString::fromUtf8(outputData
.data());
93 QStringList outputList
= output
.split('\n');
94 foreach (QString line
, outputList
) {
95 if (info
.indexIn(line
) != -1) {
96 Workgroup
= info
.cap(1);
98 Software
= info
.cap(3);
100 if (host
.indexIn(line
) != -1) {
101 Comment
= host
.cap(1);
106 delete detailsProcess
;
109 m_mainWidget
->sComment
->setText(Comment
);
110 m_mainWidget
->sWorkgroup
->setText(Workgroup
);
111 m_mainWidget
->sOS
->setText(OS
);
112 m_mainWidget
->sServer
->setText(Software
);
115 void WPUserInfo::slotCloseClicked()
122 #include "wpuserinfo.moc"
124 // vim: set noet ts=4 sts=4 sw=4:
125 // kate: tab-width 4; indent-width 4; replace-trailing-space-save on;