summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/appearance2/appearance.cpp4
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp52
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp29
3 files changed, 43 insertions, 42 deletions
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp
index f918767..9638686 100644
--- a/noncore/settings/appearance2/appearance.cpp
+++ b/noncore/settings/appearance2/appearance.cpp
@@ -1,233 +1,234 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 Copyright (c) 2002 Trolltech AS <info@trolltech.com> 3 Copyright (c) 2002 Trolltech AS <info@trolltech.com>
4 =. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4 =. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 5             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This file is free software; you can 7 _;:,     .>    :=|. This file is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This file is distributed in the hope that 14    .i_,=:_.      -<s. This file is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.=       =       ; Public License for more details. 19..}^=.=       =       ; Public License for more details.
20++=   -.     .`     .: 20++=   -.     .`     .:
21 :     =  ...= . :.=- You should have received a copy of the GNU 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 -.   .:....=;==+<; General Public License along with this file; 22 -.   .:....=;==+<; General Public License along with this file;
23  -_. . .   )=.  = see the file COPYING. If not, write to the 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "appearance.h" 30#include "appearance.h"
31#include "editScheme.h" 31#include "editScheme.h"
32#include "stylelistitem.h" 32#include "stylelistitem.h"
33#include "decolistitem.h" 33#include "decolistitem.h"
34#include "colorlistitem.h" 34#include "colorlistitem.h"
35#include "exceptlistitem.h" 35#include "exceptlistitem.h"
36#include "sample.h" 36#include "sample.h"
37 37
38/* OPIE */ 38/* OPIE */
39#include <opie2/odevice.h> 39#include <opie2/odevice.h>
40#include <opie2/ofiledialog.h> 40#include <opie2/ofiledialog.h>
41#include <opie2/otabwidget.h> 41#include <opie2/otabwidget.h>
42#include <opie2/odebug.h>
42 43
43#include <qpe/config.h> 44#include <qpe/config.h>
44#include <qpe/global.h> 45#include <qpe/global.h>
45#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
46#include <qpe/qpemessagebox.h> 47#include <qpe/qpemessagebox.h>
47#include <qpe/qcopenvelope_qws.h> 48#include <qpe/qcopenvelope_qws.h>
48#include <qpe/qpestyle.h> 49#include <qpe/qpestyle.h>
49#include <qpe/lightstyle.h> 50#include <qpe/lightstyle.h>
50#include <qpe/styleinterface.h> 51#include <qpe/styleinterface.h>
51 52
52/* QT */ 53/* QT */
53#include <qbuttongroup.h> 54#include <qbuttongroup.h>
54#include <qcheckbox.h> 55#include <qcheckbox.h>
55#include <qcombobox.h> 56#include <qcombobox.h>
56#include <qdialog.h> 57#include <qdialog.h>
57#include <qdir.h> 58#include <qdir.h>
58#include <qlabel.h> 59#include <qlabel.h>
59#include <qlayout.h> 60#include <qlayout.h>
60#include <qlineedit.h> 61#include <qlineedit.h>
61#include <qlistbox.h> 62#include <qlistbox.h>
62#include <qmessagebox.h> 63#include <qmessagebox.h>
63#include <qpushbutton.h> 64#include <qpushbutton.h>
64#include <qradiobutton.h> 65#include <qradiobutton.h>
65#if QT_VERSION >= 300 66#if QT_VERSION >= 300
66#include <qstylefactory.h> 67#include <qstylefactory.h>
67#endif 68#endif
68#include <qtoolbutton.h> 69#include <qtoolbutton.h>
69#include <qwindowsstyle.h> 70#include <qwindowsstyle.h>
70#include <qlistview.h> 71#include <qlistview.h>
71#include <qheader.h> 72#include <qheader.h>
72#include <qvbox.h> 73#include <qvbox.h>
73#include <qwhatsthis.h> 74#include <qwhatsthis.h>
74 75
75using namespace Opie; 76using namespace Opie;
76using namespace Opie::Ui; 77using namespace Opie::Ui;
77using namespace Opie::Core; 78using namespace Opie::Core;
78 79
79class DefaultWindowDecoration : public WindowDecorationInterface 80class DefaultWindowDecoration : public WindowDecorationInterface
80{ 81{
81public: 82public:
82 DefaultWindowDecoration() : ref(0) {} 83 DefaultWindowDecoration() : ref(0) {}
83 QString name() const 84 QString name() const
84 { 85 {
85 return "Default"; 86 return "Default";
86 } 87 }
87 QPixmap icon() const 88 QPixmap icon() const
88 { 89 {
89 return QPixmap(); 90 return QPixmap();
90 } 91 }
91 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) 92 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface )
92 { 93 {
93 *iface = 0; 94 *iface = 0;
94 if ( uuid == IID_QUnknown ) 95 if ( uuid == IID_QUnknown )
95 *iface = this; 96 *iface = this;
96 else if ( uuid == IID_WindowDecoration ) 97 else if ( uuid == IID_WindowDecoration )
97 *iface = this; 98 *iface = this;
98 99
99 if ( *iface ) 100 if ( *iface )
100 (*iface)->addRef(); 101 (*iface)->addRef();
101 return QS_OK; 102 return QS_OK;
102 } 103 }
103 Q_REFCOUNT 104 Q_REFCOUNT
104 105
105private: 106private:
106 ulong ref; 107 ulong ref;
107}; 108};
108 109
109 110
110 111
111 112
112 113
113 114
114 115
115QWidget *Appearance::createStyleTab ( QWidget *parent, Config &cfg ) 116QWidget *Appearance::createStyleTab ( QWidget *parent, Config &cfg )
116{ 117{
117 QWidget* tab = new QWidget( parent, "StyleTab" ); 118 QWidget* tab = new QWidget( parent, "StyleTab" );
118 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 ); 119 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
119 120
120 m_style_list = new QListBox( tab, "m_style_list" ); 121 m_style_list = new QListBox( tab, "m_style_list" );
121 vertLayout->addWidget( m_style_list ); 122 vertLayout->addWidget( m_style_list );
122 QWhatsThis::add( m_style_list, tr( "Styles control the way items such as buttons and scroll bars appear in all applications.\n\nClick here to select an available style." ) ); 123 QWhatsThis::add( m_style_list, tr( "Styles control the way items such as buttons and scroll bars appear in all applications.\n\nClick here to select an available style." ) );
123 124
124 m_style_settings = new QPushButton ( tr( "Settings..." ), tab ); 125 m_style_settings = new QPushButton ( tr( "Settings..." ), tab );
125 connect ( m_style_settings, SIGNAL( clicked()), this, SLOT( styleSettingsClicked())); 126 connect ( m_style_settings, SIGNAL( clicked()), this, SLOT( styleSettingsClicked()));
126 vertLayout-> addWidget ( m_style_settings ); 127 vertLayout-> addWidget ( m_style_settings );
127 QWhatsThis::add( m_style_settings, tr( "Click here to configure the currently selected style.\n\nNote: This option is not available for all styles." ) ); 128 QWhatsThis::add( m_style_settings, tr( "Click here to configure the currently selected style.\n\nNote: This option is not available for all styles." ) );
128 129
129 QString s = cfg. readEntry ( "Style", "Light" ); 130 QString s = cfg. readEntry ( "Style", "Light" );
130 131
131 132
132#if QT_VERSION >= 300 133#if QT_VERSION >= 300
133 m_style_list->insertStringList(QStyleFactory::styles()); 134 m_style_list->insertStringList(QStyleFactory::styles());
134#else 135#else
135 m_style_list-> insertItem ( new StyleListItem ( "Windows", new QWindowsStyle ( ))); 136 m_style_list-> insertItem ( new StyleListItem ( "Windows", new QWindowsStyle ( )));
136 m_style_list-> insertItem ( new StyleListItem ( "Light", new LightStyle ( ))); 137 m_style_list-> insertItem ( new StyleListItem ( "Light", new LightStyle ( )));
137 m_style_list-> insertItem ( new StyleListItem ( "QPE", new QPEStyle ( ))); 138 m_style_list-> insertItem ( new StyleListItem ( "QPE", new QPEStyle ( )));
138#endif 139#endif
139 140
140 { 141 {
141 QString path = QPEApplication::qpeDir ( ); 142 QString path = QPEApplication::qpeDir ( );
142 path.append( "/plugins/styles/" ); 143 path.append( "/plugins/styles/" );
143 QStringList sl = QDir ( path, "lib*.so" ). entryList ( ); 144 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
144 145
145 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 146 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
146 { 147 {
147 QString libstr = path; 148 QString libstr = path;
148 libstr.append( "/" ); 149 libstr.append( "/" );
149 libstr.append( *it ); 150 libstr.append( *it );
150 QLibrary *lib = new QLibrary ( libstr ); 151 QLibrary *lib = new QLibrary ( libstr );
151 StyleInterface *iface; 152 StyleInterface *iface;
152 153
153 if (( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK ) && iface ) 154 if (( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK ) && iface )
154 { 155 {
155 StyleListItem *slit = new StyleListItem ( lib, iface ); 156 StyleListItem *slit = new StyleListItem ( lib, iface );
156 m_style_list-> insertItem ( slit ); 157 m_style_list-> insertItem ( slit );
157 158
158 if ( slit-> key ( ) == s ) 159 if ( slit-> key ( ) == s )
159 m_style_list-> setCurrentItem ( slit ); 160 m_style_list-> setCurrentItem ( slit );
160 } 161 }
161 else 162 else
162 delete lib; 163 delete lib;
163 } 164 }
164 } 165 }
165 166
166 m_original_style = m_style_list-> currentItem ( ); 167 m_original_style = m_style_list-> currentItem ( );
167 styleClicked ( m_original_style ); 168 styleClicked ( m_original_style );
168 169
169 connect( m_style_list, SIGNAL( highlighted(int) ), this, SLOT( styleClicked(int) ) ); 170 connect( m_style_list, SIGNAL( highlighted(int) ), this, SLOT( styleClicked(int) ) );
170 171
171 return tab; 172 return tab;
172} 173}
173 174
174QWidget *Appearance::createDecoTab ( QWidget *parent, Config &cfg ) 175QWidget *Appearance::createDecoTab ( QWidget *parent, Config &cfg )
175{ 176{
176 QWidget* tab = new QWidget( parent, "DecoTab" ); 177 QWidget* tab = new QWidget( parent, "DecoTab" );
177 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 ); 178 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
178 179
179 m_deco_list = new QListBox( tab, "m_deco_list" ); 180 m_deco_list = new QListBox( tab, "m_deco_list" );
180 vertLayout->addWidget( m_deco_list ); 181 vertLayout->addWidget( m_deco_list );
181 QWhatsThis::add( m_deco_list, tr( "Window decorations control the way the application title bar and its buttons appear.\n\nClick here to select an available decoration." ) ); 182 QWhatsThis::add( m_deco_list, tr( "Window decorations control the way the application title bar and its buttons appear.\n\nClick here to select an available decoration." ) );
182 183
183 QString s = cfg. readEntry ( "Decoration", "libflat.so" ); 184 QString s = cfg. readEntry ( "Decoration", "libflat.so" );
184 185
185 m_deco_list-> insertItem ( new DecoListItem ( "QPE" )); 186 m_deco_list-> insertItem ( new DecoListItem ( "QPE" ));
186 187
187 { 188 {
188 QString path = QPEApplication::qpeDir(); 189 QString path = QPEApplication::qpeDir();
189 path.append( "/plugins/decorations/" ); 190 path.append( "/plugins/decorations/" );
190 QStringList sl = QDir ( path, "lib*.so" ). entryList ( ); 191 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
191 192
192 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 193 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
193 { 194 {
194 QString libstr = path; 195 QString libstr = path;
195 libstr.append( "/" ); 196 libstr.append( "/" );
196 libstr.append( *it ); 197 libstr.append( *it );
197 QLibrary *lib = new QLibrary ( libstr ); 198 QLibrary *lib = new QLibrary ( libstr );
198 WindowDecorationInterface *iface; 199 WindowDecorationInterface *iface;
199 200
200 if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK ) 201 if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK )
201 { 202 {
202 DecoListItem *dlit = new DecoListItem ( lib, iface ); 203 DecoListItem *dlit = new DecoListItem ( lib, iface );
203 m_deco_list-> insertItem ( dlit ); 204 m_deco_list-> insertItem ( dlit );
204 205
205 if ( dlit-> key ( ) == s ) 206 if ( dlit-> key ( ) == s )
206 m_deco_list-> setCurrentItem ( dlit ); 207 m_deco_list-> setCurrentItem ( dlit );
207 } 208 }
208 else 209 else
209 delete lib; 210 delete lib;
210 } 211 }
211 } 212 }
212 213
213 m_original_deco = m_deco_list-> currentItem ( ); 214 m_original_deco = m_deco_list-> currentItem ( );
214 if ( m_deco_list-> currentItem ( ) < 0 ) 215 if ( m_deco_list-> currentItem ( ) < 0 )
215 m_deco_list-> setCurrentItem ( 0 ); 216 m_deco_list-> setCurrentItem ( 0 );
216 decoClicked ( m_original_deco ); 217 decoClicked ( m_original_deco );
217 218
218 connect( m_deco_list, SIGNAL( highlighted(int) ), this, SLOT( decoClicked(int) ) ); 219 connect( m_deco_list, SIGNAL( highlighted(int) ), this, SLOT( decoClicked(int) ) );
219 220
220 return tab; 221 return tab;
221} 222}
222 223
223QWidget *Appearance::createFontTab ( QWidget *parent, Config &cfg ) 224QWidget *Appearance::createFontTab ( QWidget *parent, Config &cfg )
224{ 225{
225 QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" ); 226 QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" );
226 QString styleStr = cfg. readEntry ( "FontStyle", "Regular" ); 227 QString styleStr = cfg. readEntry ( "FontStyle", "Regular" );
227 int size = cfg. readNumEntry ( "FontSize", 10 ); 228 int size = cfg. readNumEntry ( "FontSize", 10 );
228 229
229 m_fontselect = new OFontSelector ( false, parent, "FontTab" ); 230 m_fontselect = new OFontSelector ( false, parent, "FontTab" );
230 m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); 231 m_fontselect-> setSelectedFont ( familyStr, styleStr, size );
231 QWhatsThis::add( m_fontselect, tr( "Select the desired name, style and size of the default font applications will use." ) ); 232 QWhatsThis::add( m_fontselect, tr( "Select the desired name, style and size of the default font applications will use." ) );
232 233
233 connect( m_fontselect, SIGNAL( fontSelected(const QFont&)), 234 connect( m_fontselect, SIGNAL( fontSelected(const QFont&)),
@@ -643,248 +644,249 @@ void Appearance::decoClicked ( int index )
643 644
644 if ( m_sample ) 645 if ( m_sample )
645 { 646 {
646 if ( dli && dli-> interface ( )) 647 if ( dli && dli-> interface ( ))
647 m_sample-> setDecoration ( dli-> interface ( )); 648 m_sample-> setDecoration ( dli-> interface ( ));
648 else 649 else
649 m_sample-> setDecoration ( new DefaultWindowDecoration ( )); 650 m_sample-> setDecoration ( new DefaultWindowDecoration ( ));
650 m_sample-> repaint ( ); 651 m_sample-> repaint ( );
651 } 652 }
652 m_deco_changed |= ( index != m_original_deco ); 653 m_deco_changed |= ( index != m_original_deco );
653} 654}
654 655
655void Appearance::fontClicked ( const QFont &f ) 656void Appearance::fontClicked ( const QFont &f )
656{ 657{
657 m_font_changed |= ( f != m_sample-> font ( )); 658 m_font_changed |= ( f != m_sample-> font ( ));
658 m_sample-> setFont ( f ); 659 m_sample-> setFont ( f );
659} 660}
660 661
661void Appearance::colorClicked ( int index ) 662void Appearance::colorClicked ( int index )
662{ 663{
663 ColorListItem *item = (ColorListItem *) m_color_list-> item ( index ); 664 ColorListItem *item = (ColorListItem *) m_color_list-> item ( index );
664 665
665 if ( item ) 666 if ( item )
666 m_sample-> setPalette ( item-> palette ( )); 667 m_sample-> setPalette ( item-> palette ( ));
667 668
668 m_color_changed |= ( item-> palette ( ) != qApp-> palette ( )); 669 m_color_changed |= ( item-> palette ( ) != qApp-> palette ( ));
669} 670}
670 671
671 672
672void Appearance::editSchemeClicked ( ) 673void Appearance::editSchemeClicked ( )
673{ 674{
674 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 675 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
675 676
676 int cnt = 0; 677 int cnt = 0;
677 QString labels [QColorGroup::NColorRoles]; 678 QString labels [QColorGroup::NColorRoles];
678 QColor colors [QColorGroup::NColorRoles]; 679 QColor colors [QColorGroup::NColorRoles];
679 680
680 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role ) 681 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
681 { 682 {
682 QColor col = item->color( static_cast<QColorGroup::ColorRole>( role ) ); 683 QColor col = item->color( static_cast<QColorGroup::ColorRole>( role ) );
683 684
684 if ( col. isValid ( )) 685 if ( col. isValid ( ))
685 { 686 {
686 labels[cnt] = item->label( static_cast<QColorGroup::ColorRole>( role ) ); 687 labels[cnt] = item->label( static_cast<QColorGroup::ColorRole>( role ) );
687 colors[cnt] = col; 688 colors[cnt] = col;
688 689
689 cnt++; 690 cnt++;
690 } 691 }
691 } 692 }
692 693
693 EditScheme* editdlg = new EditScheme( cnt, labels, colors, this, "editScheme", true ); 694 EditScheme* editdlg = new EditScheme( cnt, labels, colors, this, "editScheme", true );
694 if ( QPEApplication::execDialog( editdlg ) == QDialog::Accepted ) 695 if ( QPEApplication::execDialog( editdlg ) == QDialog::Accepted )
695 { 696 {
696 ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 ); 697 ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 );
697 cnt = 0; 698 cnt = 0;
698 699
699 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role ) 700 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
700 { 701 {
701 if ( item->color( static_cast<QColorGroup::ColorRole>( role ) ).isValid() ) 702 if ( item->color( static_cast<QColorGroup::ColorRole>( role ) ).isValid() )
702 { 703 {
703 citem->setColor( static_cast<QColorGroup::ColorRole>( role ), colors[cnt] ); 704 citem->setColor( static_cast<QColorGroup::ColorRole>( role ), colors[cnt] );
704 cnt++; 705 cnt++;
705 } 706 }
706 } 707 }
707 708
708 m_color_list-> setCurrentItem ( 0 ); 709 m_color_list-> setCurrentItem ( 0 );
709 colorClicked ( 0 ); 710 colorClicked ( 0 );
710 711
711 m_color_changed = true; 712 m_color_changed = true;
712 } 713 }
713 delete editdlg; 714 delete editdlg;
714} 715}
715 716
716 717
717void Appearance::saveSchemeClicked() 718void Appearance::saveSchemeClicked()
718{ 719{
719 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 720 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
720 721
721 if ( !item ) 722 if ( !item )
722 return; 723 return;
723 724
724 QDialog *d = new QDialog ( this, 0, true ); 725 QDialog *d = new QDialog ( this, 0, true );
725 d-> setCaption ( tr( "Save Scheme" )); 726 d-> setCaption ( tr( "Save Scheme" ));
726 QLineEdit *ed = new QLineEdit ( d ); 727 QLineEdit *ed = new QLineEdit ( d );
727 ( new QVBoxLayout ( d, 3, 3 ))-> addWidget ( ed ); 728 ( new QVBoxLayout ( d, 3, 3 ))-> addWidget ( ed );
728 ed-> setFocus ( ); 729 ed-> setFocus ( );
729 730
730 if ( d-> exec ( ) == QDialog::Accepted ) 731 if ( d-> exec ( ) == QDialog::Accepted )
731 { 732 {
732 QString schemename = ed-> text ( ); 733 QString schemename = ed-> text ( );
733 QString filestr = QPEApplication::qpeDir(); 734 QString filestr = QPEApplication::qpeDir();
734 filestr.append( "/etc/colors/" ); 735 filestr.append( "/etc/colors/" );
735 filestr.append( schemename ); 736 filestr.append( schemename );
736 filestr.append( ".scheme" ); 737 filestr.append( ".scheme" );
737 QFile file ( filestr ); 738 QFile file ( filestr );
738 if ( !file. exists ( )) 739 if ( !file. exists ( ))
739 { 740 {
740 QPalette p = item-> palette ( ); 741 QPalette p = item-> palette ( );
741 742
742 Config config ( file.name(), Config::File ); 743 Config config ( file.name(), Config::File );
743 config. setGroup( "Colors" ); 744 config. setGroup( "Colors" );
744 745
745 item-> save ( config ); 746 item-> save ( config );
746 747
747 config. write ( ); // need to flush the config info first 748 config. write ( ); // need to flush the config info first
748 749
749 m_color_list-> insertItem ( new ColorListItem ( schemename, config )); 750 m_color_list-> insertItem ( new ColorListItem ( schemename, config ));
750 } 751 }
751 else 752 else
752 { 753 {
753 QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." )); 754 QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." ));
754 } 755 }
755 } 756 }
756 delete d; 757 delete d;
757} 758}
758 759
759void Appearance::deleteSchemeClicked() 760void Appearance::deleteSchemeClicked()
760{ 761{
761 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 762 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
762 763
763 if ( !item ) 764 if ( !item )
764 return; 765 return;
765 766
766 if ( m_color_list-> currentItem ( ) > 0 ) 767 if ( m_color_list-> currentItem ( ) > 0 )
767 { 768 {
768 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete scheme" ), item-> text ( ) ) ) 769 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete scheme" ), item-> text ( ) ) )
769 { 770 {
770 QString filestr = QPEApplication::qpeDir ( ); 771 QString filestr = QPEApplication::qpeDir ( );
771 filestr.append( "/etc/colors/" ); 772 filestr.append( "/etc/colors/" );
772 filestr.append( item-> text ( ) ); 773 filestr.append( item-> text ( ) );
773 filestr.append( ".scheme" ); 774 filestr.append( ".scheme" );
774 QFile::remove ( filestr ); 775 QFile::remove ( filestr );
775 delete item; 776 delete item;
776 } 777 }
777 } 778 }
778 else 779 else
779 { 780 {
780 QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." )); 781 QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." ));
781 } 782 }
782} 783}
783 784
784 785
785void Appearance::addExcept ( ) 786void Appearance::addExcept ( )
786{ 787{
787 ExceptListItem *it = new ExceptListItem ( m_except, 0, tr( "<new>" ), true, true, true ); 788 ExceptListItem *it = new ExceptListItem ( m_except, 0, tr( "<new>" ), true, true, true );
788 m_except-> ensureItemVisible ( it ); 789 m_except-> ensureItemVisible ( it );
789 m_except-> setSelected ( it, true ); 790 m_except-> setSelected ( it, true );
790} 791}
791 792
792void Appearance::delExcept ( ) 793void Appearance::delExcept ( )
793{ 794{
794 if ( m_except-> selectedItem ( )) 795 if ( m_except-> selectedItem ( ))
795 { 796 {
796 m_except-> setFocus ( ); 797 m_except-> setFocus ( );
797 delete m_except-> selectedItem ( ); 798 delete m_except-> selectedItem ( );
798 } 799 }
799} 800}
800 801
801void Appearance::upExcept ( ) 802void Appearance::upExcept ( )
802{ 803{
803 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( ); 804 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( );
804 805
805 if ( it && it-> itemAbove ( )) 806 if ( it && it-> itemAbove ( ))
806 it-> itemAbove ( )-> moveItem ( it ); 807 it-> itemAbove ( )-> moveItem ( it );
807} 808}
808 809
809void Appearance::downExcept ( ) 810void Appearance::downExcept ( )
810{ 811{
811 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( ); 812 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( );
812 813
813 if ( it && it-> itemBelow ( )) 814 if ( it && it-> itemBelow ( ))
814 it-> moveItem ( it-> itemBelow ( )); 815 it-> moveItem ( it-> itemBelow ( ));
815} 816}
816 817
817class ExEdit : public QLineEdit 818class ExEdit : public QLineEdit
818{ 819{
819public: 820public:
820 ExEdit ( ExceptListItem *item ) 821 ExEdit ( ExceptListItem *item )
821 : QLineEdit ( item-> listView ( )-> viewport ( ), "exedit" ), it ( item ) 822 : QLineEdit ( item-> listView ( )-> viewport ( ), "exedit" ), it ( item )
822 { 823 {
823 setFrame ( false ); 824 setFrame ( false );
824 825
825 QRect r = it-> listView ( )-> itemRect ( it ); 826 QRect r = it-> listView ( )-> itemRect ( it );
826 827
827 int x = it-> listView ( )-> header ( )-> cellPos ( 3 ) - 1; 828 int x = it-> listView ( )-> header ( )-> cellPos ( 3 ) - 1;
828 int y = r. y ( ); 829 int y = r. y ( );
829 int w = it-> listView ( )-> viewport ( )-> width ( ) - x; 830 int w = it-> listView ( )-> viewport ( )-> width ( ) - x;
830 int h = r. height ( ); // + 2; 831 int h = r. height ( ); // + 2;
831 832
832 setText ( it-> pattern ( )); 833 setText ( it-> pattern ( ));
833 setGeometry ( x, y, w, h ); 834 setGeometry ( x, y, w, h );
834 835
835 qDebug ( "ExEdit: [%s] at %d,%d %d,%d", it->text(2).latin1(),x,y,w,h); 836 odebug << "ExEdit: [" << it->text(2).latin1() << "] at "
837 << x << "," << y << " " << w << "," << h << oendl;
836 838
837 m_out = true; 839 m_out = true;
838 840
839 show ( ); 841 show ( );
840 setFocus ( ); 842 setFocus ( );
841 selectAll ( ); 843 selectAll ( );
842 end ( true ); 844 end ( true );
843 } 845 }
844 846
845 virtual void focusOutEvent ( QFocusEvent * ) 847 virtual void focusOutEvent ( QFocusEvent * )
846 { 848 {
847 hide ( ); 849 hide ( );
848 if ( m_out ) 850 if ( m_out )
849 it-> setPattern ( text ( )); 851 it-> setPattern ( text ( ));
850 delete this; 852 delete this;
851 } 853 }
852 854
853 virtual void keyPressEvent ( QKeyEvent *e ) 855 virtual void keyPressEvent ( QKeyEvent *e )
854 { 856 {
855 if ( e-> key ( ) == Key_Return ) 857 if ( e-> key ( ) == Key_Return )
856 it-> listView ( )-> setFocus ( ); 858 it-> listView ( )-> setFocus ( );
857 else if ( e-> key ( ) == Key_Escape ) 859 else if ( e-> key ( ) == Key_Escape )
858 { 860 {
859 m_out = false; 861 m_out = false;
860 it-> listView ( )-> setFocus ( ); 862 it-> listView ( )-> setFocus ( );
861 } 863 }
862 else 864 else
863 QLineEdit::keyPressEvent ( e ); 865 QLineEdit::keyPressEvent ( e );
864 } 866 }
865 867
866private: 868private:
867 ExceptListItem *it; 869 ExceptListItem *it;
868 bool m_out; 870 bool m_out;
869}; 871};
870 872
871void Appearance::clickedExcept ( QListViewItem *item, const QPoint &, int c ) 873void Appearance::clickedExcept ( QListViewItem *item, const QPoint &, int c )
872{ 874{
873 if ( !item || c < 0 || c > 3 ) 875 if ( !item || c < 0 || c > 3 )
874 return; 876 return;
875 877
876 ExceptListItem *it = (ExceptListItem *) item; 878 ExceptListItem *it = (ExceptListItem *) item;
877 879
878 if ( c == 0 ) 880 if ( c == 0 )
879 it-> setNoStyle ( !it-> noStyle ( )); 881 it-> setNoStyle ( !it-> noStyle ( ));
880 else if ( c == 1 ) 882 else if ( c == 1 )
881 it-> setNoFont ( !it-> noFont ( )); 883 it-> setNoFont ( !it-> noFont ( ));
882 else if ( c == 2 ) 884 else if ( c == 2 )
883 it-> setNoDeco ( !it-> noDeco ( )); 885 it-> setNoDeco ( !it-> noDeco ( ));
884 else if ( c == 3 ) 886 else if ( c == 3 )
885 { 887 {
886 m_except-> ensureItemVisible ( it ); 888 m_except-> ensureItemVisible ( it );
887 new ExEdit ( it ); 889 new ExEdit ( it );
888 } 890 }
889} 891}
890 892
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 5913a22..3bc7d43 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -1,1085 +1,1085 @@
1/* 1/*
2 * kPPP: A pppd Front End for the KDE project 2 * kPPP: A pppd Front End for the KDE project
3 * 3 *
4 * $Id$ 4 * $Id$
5 * 5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben 6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu 7 * wuebben@math.cornell.edu
8 * 8 *
9 * This file was added by Harri Porten <porten@tu-harburg.de> 9 * This file was added by Harri Porten <porten@tu-harburg.de>
10 * 10 *
11 * 11 *
12 * This program is free software; you can redistribute it and/or 12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public 13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either 14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version. 15 * version 2 of the License, or (at your option) any later version.
16 * 16 *
17 * This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details. 20 * Library General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU Library General Public 22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free 23 * License along with this program; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27/* OPIE */ 27/* OPIE */
28#include <opie2/odebug.h> 28#include <opie2/odebug.h>
29using namespace Opie::Core; 29using namespace Opie::Core;
30 30
31/* STD */ 31/* STD */
32#include <errno.h> 32#include <errno.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <signal.h> 36#include <signal.h>
37#include <sys/ioctl.h> 37#include <sys/ioctl.h>
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/stat.h> 39#include <sys/stat.h>
40#include <setjmp.h> 40#include <setjmp.h>
41#include <regex.h> 41#include <regex.h>
42#include <qregexp.h> 42#include <qregexp.h>
43#include <assert.h> 43#include <assert.h>
44#include <string.h> 44#include <string.h>
45 45
46#ifdef HAVE_RESOLV_H 46#ifdef HAVE_RESOLV_H
47# include <arpa/nameser.h> 47# include <arpa/nameser.h>
48# include <resolv.h> 48# include <resolv.h>
49#endif 49#endif
50 50
51#ifndef _PATH_RESCONF 51#ifndef _PATH_RESCONF
52#define _PATH_RESCONF "/etc/resolv.conf" 52#define _PATH_RESCONF "/etc/resolv.conf"
53#endif 53#endif
54 54
55#define strlcpy strcpy 55#define strlcpy strcpy
56#include "auth.h" 56#include "auth.h"
57#include "modem.h" 57#include "modem.h"
58#include "pppdata.h" 58#include "pppdata.h"
59#define qError qDebug 59#define qError qDebug
60 60
61 61
62#define MY_ASSERT(x) if (!(x)) { \ 62#define MY_ASSERT(x) if (!(x)) { \
63 ofatal << "ASSERT: \"" << #x << "\" in " << __FILE__ << " (" << __LINE__ << ")\n" << oendl; \ 63 ofatal << "ASSERT: \"" << #x << "\" in " << __FILE__ << " (" << __LINE__ << ")\n" << oendl; \
64 exit(1); } 64 exit(1); }
65 65
66 66
67static sigjmp_buf jmp_buffer; 67static sigjmp_buf jmp_buffer;
68 68
69//Modem *Modem::modem = 0; 69//Modem *Modem::modem = 0;
70 70
71 71
72const char* pppdPath() { 72const char* pppdPath() {
73 // wasting a few bytes 73 // wasting a few bytes
74 static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; 74 static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)];
75 static char *pppdPath = 0L; 75 static char *pppdPath = 0L;
76 char *p; 76 char *p;
77 77
78 if(pppdPath == 0L) { 78 if(pppdPath == 0L) {
79 const char *c = PPPDSEARCHPATH; 79 const char *c = PPPDSEARCHPATH;
80 while(*c != '\0') { 80 while(*c != '\0') {
81 while(*c == ':') 81 while(*c == ':')
82 c++; 82 c++;
83 p = buffer; 83 p = buffer;
84 while(*c != '\0' && *c != ':') 84 while(*c != '\0' && *c != ':')
85 *p++ = *c++; 85 *p++ = *c++;
86 *p = '\0'; 86 *p = '\0';
87 strcat(p, "/"); 87 strcat(p, "/");
88 strcat(p, PPPDNAME); 88 strcat(p, PPPDNAME);
89 if(access(buffer, F_OK) == 0) 89 if(access(buffer, F_OK) == 0)
90 return (pppdPath = buffer); 90 return (pppdPath = buffer);
91 } 91 }
92 } 92 }
93 93
94 return pppdPath; 94 return pppdPath;
95} 95}
96 96
97 97
98Modem::Modem( PPPData* pd ) 98Modem::Modem( PPPData* pd )
99{ 99{
100 _pppdata = pd; 100 _pppdata = pd;
101 modemfd = -1; 101 modemfd = -1;
102 _pppdExitStatus = -1; 102 _pppdExitStatus = -1;
103 pppdPid = -1; 103 pppdPid = -1;
104 sn = m_modemDebug = 0L; 104 sn = m_modemDebug = 0L;
105 data_mode = false; 105 data_mode = false;
106 modem_is_locked = false; 106 modem_is_locked = false;
107 lockfile[0] = '\0'; 107 lockfile[0] = '\0';
108 device = "/dev/modem"; 108 device = "/dev/modem";
109} 109}
110 110
111 111
112Modem::~Modem() 112Modem::~Modem()
113{ 113{
114} 114}
115 115
116 116
117speed_t Modem::modemspeed() { 117speed_t Modem::modemspeed() {
118 // convert the string modem speed int the gpppdata object to a t_speed type 118 // convert the string modem speed int the gpppdata object to a t_speed type
119 // to set the modem. The constants here should all be ifdef'd because 119 // to set the modem. The constants here should all be ifdef'd because
120 // other systems may not have them 120 // other systems may not have them
121 int i = _pppdata->speed().toInt()/100; 121 int i = _pppdata->speed().toInt()/100;
122 122
123 switch(i) { 123 switch(i) {
124 case 24: 124 case 24:
125 return B2400; 125 return B2400;
126 break; 126 break;
127 case 96: 127 case 96:
128 return B9600; 128 return B9600;
129 break; 129 break;
130 case 192: 130 case 192:
131 return B19200; 131 return B19200;
132 break; 132 break;
133 case 384: 133 case 384:
134 return B38400; 134 return B38400;
135 break; 135 break;
136#ifdef B57600 136#ifdef B57600
137 case 576: 137 case 576:
138 return B57600; 138 return B57600;
139 break; 139 break;
140#endif 140#endif
141 141
142#ifdef B115200 142#ifdef B115200
143 case 1152: 143 case 1152:
144 return B115200; 144 return B115200;
145 break; 145 break;
146#endif 146#endif
147 147
148#ifdef B230400 148#ifdef B230400
149 case 2304: 149 case 2304:
150 return B230400; 150 return B230400;
151 break; 151 break;
152#endif 152#endif
153 153
154#ifdef B460800 154#ifdef B460800
155 case 4608: 155 case 4608:
156 return B460800; 156 return B460800;
157 break; 157 break;
158#endif 158#endif
159 159
160 default: 160 default:
161 return B38400; 161 return B38400;
162 break; 162 break;
163 } 163 }
164} 164}
165 165
166bool Modem::opentty() { 166bool Modem::opentty() {
167 // int flags; 167 // int flags;
168 168
169//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { 169//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
170 close(modemfd); 170 close(modemfd);
171 device = _pppdata->modemDevice(); 171 device = _pppdata->modemDevice();
172 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { 172 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
173 odebug << "error opening modem device !" << oendl; 173 odebug << "error opening modem device !" << oendl;
174 errmsg = QObject::tr("Unable to open modem."); 174 errmsg = QObject::tr("Unable to open modem.");
175 return false; 175 return false;
176 } 176 }
177//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { 177//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
178//} 178//}
179 179
180#if 0 180#if 0
181 if(_pppdata->UseCDLine()) { 181 if(_pppdata->UseCDLine()) {
182 if(ioctl(modemfd, TIOCMGET, &flags) == -1) { 182 if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
183 errmsg = QObject::tr("Unable to detect state of CD line."); 183 errmsg = QObject::tr("Unable to detect state of CD line.");
184 ::close(modemfd); 184 ::close(modemfd);
185 modemfd = -1; 185 modemfd = -1;
186 return false; 186 return false;
187 } 187 }
188 if ((flags&TIOCM_CD) == 0) { 188 if ((flags&TIOCM_CD) == 0) {
189 errmsg = QObject::tr("The modem is not ready."); 189 errmsg = QObject::tr("The modem is not ready.");
190 ::close(modemfd); 190 ::close(modemfd);
191 modemfd = -1; 191 modemfd = -1;
192 return false; 192 return false;
193 } 193 }
194 } 194 }
195#endif 195#endif
196 196
197 tcdrain (modemfd); 197 tcdrain (modemfd);
198 tcflush (modemfd, TCIOFLUSH); 198 tcflush (modemfd, TCIOFLUSH);
199 199
200 if(tcgetattr(modemfd, &tty) < 0){ 200 if(tcgetattr(modemfd, &tty) < 0){
201 // this helps in some cases 201 // this helps in some cases
202 tcsendbreak(modemfd, 0); 202 tcsendbreak(modemfd, 0);
203 sleep(1); 203 sleep(1);
204 if(tcgetattr(modemfd, &tty) < 0){ 204 if(tcgetattr(modemfd, &tty) < 0){
205 errmsg = QObject::tr("The modem is busy."); 205 errmsg = QObject::tr("The modem is busy.");
206 ::close(modemfd); 206 ::close(modemfd);
207 modemfd = -1; 207 modemfd = -1;
208 return false; 208 return false;
209 } 209 }
210 } 210 }
211 211
212 memset(&initial_tty,'\0',sizeof(initial_tty)); 212 memset(&initial_tty,'\0',sizeof(initial_tty));
213 213
214 initial_tty = tty; 214 initial_tty = tty;
215 215
216 tty.c_cc[VMIN] = 0; // nonblocking 216 tty.c_cc[VMIN] = 0; // nonblocking
217 tty.c_cc[VTIME] = 0; 217 tty.c_cc[VTIME] = 0;
218 tty.c_oflag = 0; 218 tty.c_oflag = 0;
219 tty.c_lflag = 0; 219 tty.c_lflag = 0;
220 220
221 tty.c_cflag &= ~(CSIZE | CSTOPB | PARENB); 221 tty.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
222 tty.c_cflag |= CS8 | CREAD; 222 tty.c_cflag |= CS8 | CREAD;
223 tty.c_cflag |= CLOCAL; // ignore modem status lines 223 tty.c_cflag |= CLOCAL; // ignore modem status lines
224 tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ; 224 tty.c_iflag = IGNBRK | IGNPAR /* | ISTRIP */ ;
225 tty.c_lflag &= ~ICANON; // non-canonical mode 225 tty.c_lflag &= ~ICANON; // non-canonical mode
226 tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE); 226 tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHOKE);
227 227
228 228
229 if(_pppdata->flowcontrol() != "None") { 229 if(_pppdata->flowcontrol() != "None") {
230 if(_pppdata->flowcontrol() == "CRTSCTS") { 230 if(_pppdata->flowcontrol() == "CRTSCTS") {
231 tty.c_cflag |= CRTSCTS; 231 tty.c_cflag |= CRTSCTS;
232 } 232 }
233 else { 233 else {
234 tty.c_iflag |= IXON | IXOFF; 234 tty.c_iflag |= IXON | IXOFF;
235 tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ 235 tty.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
236 tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ 236 tty.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
237 } 237 }
238 } 238 }
239 else { 239 else {
240 tty.c_cflag &= ~CRTSCTS; 240 tty.c_cflag &= ~CRTSCTS;
241 tty.c_iflag &= ~(IXON | IXOFF); 241 tty.c_iflag &= ~(IXON | IXOFF);
242 } 242 }
243 243
244 cfsetospeed(&tty, modemspeed()); 244 cfsetospeed(&tty, modemspeed());
245 cfsetispeed(&tty, modemspeed()); 245 cfsetispeed(&tty, modemspeed());
246 246
247 tcdrain(modemfd); 247 tcdrain(modemfd);
248 248
249 if(tcsetattr(modemfd, TCSANOW, &tty) < 0){ 249 if(tcsetattr(modemfd, TCSANOW, &tty) < 0){
250 errmsg = QObject::tr("The modem is busy."); 250 errmsg = QObject::tr("The modem is busy.");
251 ::close(modemfd); 251 ::close(modemfd);
252 modemfd=-1; 252 modemfd=-1;
253 return false; 253 return false;
254 } 254 }
255 255
256 errmsg = QObject::tr("Modem Ready."); 256 errmsg = QObject::tr("Modem Ready.");
257 return true; 257 return true;
258} 258}
259 259
260 260
261bool Modem::closetty() { 261bool Modem::closetty() {
262 if(modemfd >=0 ) { 262 if(modemfd >=0 ) {
263 stop(); 263 stop();
264 /* discard data not read or transmitted */ 264 /* discard data not read or transmitted */
265 tcflush(modemfd, TCIOFLUSH); 265 tcflush(modemfd, TCIOFLUSH);
266 266
267 if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){ 267 if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){
268 errmsg = QObject::tr("Can't restore tty settings: tcsetattr()\n"); 268 errmsg = QObject::tr("Can't restore tty settings: tcsetattr()\n");
269 ::close(modemfd); 269 ::close(modemfd);
270 modemfd = -1; 270 modemfd = -1;
271 return false; 271 return false;
272 } 272 }
273 ::close(modemfd); 273 ::close(modemfd);
274 modemfd = -1; 274 modemfd = -1;
275 } 275 }
276 276
277 return true; 277 return true;
278} 278}
279 279
280 280
281void Modem::readtty(int) { 281void Modem::readtty(int) {
282 char buffer[200]; 282 char buffer[200];
283 unsigned char c; 283 unsigned char c;
284 int len; 284 int len;
285 285
286 // read data in chunks of up to 200 bytes 286 // read data in chunks of up to 200 bytes
287 if((len = ::read(modemfd, buffer, 200)) > 0) { 287 if((len = ::read(modemfd, buffer, 200)) > 0) {
288 // split buffer into single characters for further processing 288 // split buffer into single characters for further processing
289 for(int i = 0; i < len; i++) { 289 for(int i = 0; i < len; i++) {
290 c = buffer[i] & 0x7F; 290 c = buffer[i] & 0x7F;
291 emit charWaiting(c); 291 emit charWaiting(c);
292 } 292 }
293 } 293 }
294} 294}
295 295
296 296
297void Modem::notify(const QObject *receiver, const char *member) { 297void Modem::notify(const QObject *receiver, const char *member) {
298 connect(this, SIGNAL(charWaiting(unsigned char)), receiver, member); 298 connect(this, SIGNAL(charWaiting(unsigned char)), receiver, member);
299 startNotifier(); 299 startNotifier();
300} 300}
301 301
302 302
303void Modem::stop() { 303void Modem::stop() {
304 disconnect(SIGNAL(charWaiting(unsigned char))); 304 disconnect(SIGNAL(charWaiting(unsigned char)));
305 stopNotifier(); 305 stopNotifier();
306} 306}
307 307
308 308
309void Modem::startNotifier() { 309void Modem::startNotifier() {
310 if(modemfd >= 0) { 310 if(modemfd >= 0) {
311 if(sn == 0) { 311 if(sn == 0) {
312 sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this); 312 sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this);
313 connect(sn, SIGNAL(activated(int)), SLOT(readtty(int))); 313 connect(sn, SIGNAL(activated(int)), SLOT(readtty(int)));
314 odebug << "QSocketNotifier started!" << oendl; 314 odebug << "QSocketNotifier started!" << oendl;
315 } else { 315 } else {
316 odebug << "QSocketNotifier re-enabled!" << oendl; 316 odebug << "QSocketNotifier re-enabled!" << oendl;
317 sn->setEnabled(true); 317 sn->setEnabled(true);
318 } 318 }
319 } 319 }
320} 320}
321 321
322 322
323void Modem::stopNotifier() { 323void Modem::stopNotifier() {
324 if(sn != 0) { 324 if(sn != 0) {
325 sn->setEnabled(false); 325 sn->setEnabled(false);
326 disconnect(sn); 326 disconnect(sn);
327 delete sn; 327 delete sn;
328 sn = 0; 328 sn = 0;
329 odebug << "QSocketNotifier stopped!" << oendl; 329 odebug << "QSocketNotifier stopped!" << oendl;
330 } 330 }
331} 331}
332 332
333 333
334void Modem::flush() { 334void Modem::flush() {
335 char c; 335 char c;
336 while(read(modemfd, &c, 1) == 1); 336 while(read(modemfd, &c, 1) == 1);
337} 337}
338 338
339 339
340bool Modem::writeChar(unsigned char c) { 340bool Modem::writeChar(unsigned char c) {
341 int s; 341 int s;
342 do { 342 do {
343 s = write(modemfd, &c, 1); 343 s = write(modemfd, &c, 1);
344 if (s < 0) { 344 if (s < 0) {
345 oerr << "write() in Modem::writeChar failed" << oendl; 345 oerr << "write() in Modem::writeChar failed" << oendl;
346 return false; 346 return false;
347 } 347 }
348 } while(s == 0); 348 } while(s == 0);
349 349
350 return true; 350 return true;
351} 351}
352 352
353 353
354bool Modem::writeLine(const char *buf) { 354bool Modem::writeLine(const char *buf) {
355 int len = strlen(buf); 355 int len = strlen(buf);
356 char *b = new char[len+2]; 356 char *b = new char[len+2];
357 memcpy(b, buf, len); 357 memcpy(b, buf, len);
358 // different modems seem to need different line terminations 358 // different modems seem to need different line terminations
359 QString term = _pppdata->enter(); 359 QString term = _pppdata->enter();
360 if(term == "LF") 360 if(term == "LF")
361 b[len++]='\n'; 361 b[len++]='\n';
362 else if(term == "CR") 362 else if(term == "CR")
363 b[len++]='\r'; 363 b[len++]='\r';
364 else if(term == "CR/LF") { 364 else if(term == "CR/LF") {
365 b[len++]='\r'; 365 b[len++]='\r';
366 b[len++]='\n'; 366 b[len++]='\n';
367 } 367 }
368 int l = len; 368 int l = len;
369 while(l) { 369 while(l) {
370 int wr = write(modemfd, &b[len-l], l); 370 int wr = write(modemfd, &b[len-l], l);
371 if(wr < 0) { 371 if(wr < 0) {
372 // TODO do something meaningful with the error code (or ignore it 372 // TODO do something meaningful with the error code (or ignore it
373 oerr << "write() in Modem::writeLine failed" << oendl; 373 oerr << "write() in Modem::writeLine failed" << oendl;
374 delete[] b; 374 delete[] b;
375 return false; 375 return false;
376 } 376 }
377 l -= wr; 377 l -= wr;
378 } 378 }
379 delete[] b; 379 delete[] b;
380 return true; 380 return true;
381} 381}
382 382
383 383
384bool Modem::hangup() { 384bool Modem::hangup() {
385 // this should really get the modem to hang up and go into command mode 385 // this should really get the modem to hang up and go into command mode
386 // If anyone sees a fault in the following please let me know, since 386 // If anyone sees a fault in the following please let me know, since
387 // this is probably the most imporant snippet of code in the whole of 387 // this is probably the most imporant snippet of code in the whole of
388 // kppp. If people complain about kppp being stuck, this piece of code 388 // kppp. If people complain about kppp being stuck, this piece of code
389 // is most likely the reason. 389 // is most likely the reason.
390 struct termios temptty; 390 struct termios temptty;
391 391
392 if(modemfd >= 0) { 392 if(modemfd >= 0) {
393 393
394 // is this Escape & HangupStr stuff really necessary ? (Harri) 394 // is this Escape & HangupStr stuff really necessary ? (Harri)
395 395
396 if (data_mode) escape_to_command_mode(); 396 if (data_mode) escape_to_command_mode();
397 397
398 // Then hangup command 398 // Then hangup command
399 writeLine(_pppdata->modemHangupStr().local8Bit()); 399 writeLine(_pppdata->modemHangupStr().local8Bit());
400 400
401 usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 sec 401 usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 sec
402 402
403#ifndef DEBUG_WO_DIALING 403#ifndef DEBUG_WO_DIALING
404 if (sigsetjmp(jmp_buffer, 1) == 0) { 404 if (sigsetjmp(jmp_buffer, 1) == 0) {
405 // set alarm in case tcsendbreak() hangs 405 // set alarm in case tcsendbreak() hangs
406 signal(SIGALRM, alarm_handler); 406 signal(SIGALRM, alarm_handler);
407 alarm(2); 407 alarm(2);
408 408
409 tcsendbreak(modemfd, 0); 409 tcsendbreak(modemfd, 0);
410 410
411 alarm(0); 411 alarm(0);
412 signal(SIGALRM, SIG_IGN); 412 signal(SIGALRM, SIG_IGN);
413 } else { 413 } else {
414 // we reach this point if the alarm handler got called 414 // we reach this point if the alarm handler got called
415 closetty(); 415 closetty();
416 close(modemfd); 416 close(modemfd);
417 modemfd = -1; 417 modemfd = -1;
418 errmsg = QObject::tr("The modem does not respond."); 418 errmsg = QObject::tr("The modem does not respond.");
419 return false; 419 return false;
420 } 420 }
421 421
422#ifndef __svr4__ // drops DTR but doesn't set it afterwards again. not good for init. 422#ifndef __svr4__ // drops DTR but doesn't set it afterwards again. not good for init.
423 tcgetattr(modemfd, &temptty); 423 tcgetattr(modemfd, &temptty);
424 cfsetospeed(&temptty, B0); 424 cfsetospeed(&temptty, B0);
425 cfsetispeed(&temptty, B0); 425 cfsetispeed(&temptty, B0);
426 tcsetattr(modemfd, TCSAFLUSH, &temptty); 426 tcsetattr(modemfd, TCSAFLUSH, &temptty);
427#else 427#else
428 int modemstat; 428 int modemstat;
429 ioctl(modemfd, TIOCMGET, &modemstat); 429 ioctl(modemfd, TIOCMGET, &modemstat);
430 modemstat &= ~TIOCM_DTR; 430 modemstat &= ~TIOCM_DTR;
431 ioctl(modemfd, TIOCMSET, &modemstat); 431 ioctl(modemfd, TIOCMSET, &modemstat);
432 ioctl(modemfd, TIOCMGET, &modemstat); 432 ioctl(modemfd, TIOCMGET, &modemstat);
433 modemstat |= TIOCM_DTR; 433 modemstat |= TIOCM_DTR;
434 ioctl(modemfd, TIOCMSET, &modemstat); 434 ioctl(modemfd, TIOCMSET, &modemstat);
435#endif 435#endif
436 436
437 usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 secs 437 usleep(_pppdata->modemInitDelay() * 10000); // 0.01 - 3.0 secs
438 438
439 cfsetospeed(&temptty, modemspeed()); 439 cfsetospeed(&temptty, modemspeed());
440 cfsetispeed(&temptty, modemspeed()); 440 cfsetispeed(&temptty, modemspeed());
441 tcsetattr(modemfd, TCSAFLUSH, &temptty); 441 tcsetattr(modemfd, TCSAFLUSH, &temptty);
442#endif 442#endif
443 return true; 443 return true;
444 } else 444 } else
445 return false; 445 return false;
446} 446}
447 447
448 448
449void Modem::escape_to_command_mode() { 449void Modem::escape_to_command_mode() {
450 // Send Properly bracketed escape code to put the modem back into command state. 450 // Send Properly bracketed escape code to put the modem back into command state.
451 // A modem will accept AT commands only when it is in command state. 451 // A modem will accept AT commands only when it is in command state.
452 // When a modem sends the host the CONNECT string, that signals 452 // When a modem sends the host the CONNECT string, that signals
453 // that the modem is now in the connect state (no long accepts AT commands.) 453 // that the modem is now in the connect state (no long accepts AT commands.)
454 // Need to send properly timed escape sequence to put modem in command state. 454 // Need to send properly timed escape sequence to put modem in command state.
455 // Escape codes and guard times are controlled by S2 and S12 values. 455 // Escape codes and guard times are controlled by S2 and S12 values.
456 // 456 //
457 tcflush(modemfd, TCIOFLUSH); 457 tcflush(modemfd, TCIOFLUSH);
458 458
459 // +3 because quiet time must be greater than guard time. 459 // +3 because quiet time must be greater than guard time.
460 usleep((_pppdata->modemEscapeGuardTime()+3)*20000); 460 usleep((_pppdata->modemEscapeGuardTime()+3)*20000);
461 QCString tmp = _pppdata->modemEscapeStr().local8Bit(); 461 QCString tmp = _pppdata->modemEscapeStr().local8Bit();
462 write(modemfd, tmp.data(), tmp.length()); 462 write(modemfd, tmp.data(), tmp.length());
463 tcflush(modemfd, TCIOFLUSH); 463 tcflush(modemfd, TCIOFLUSH);
464 usleep((_pppdata->modemEscapeGuardTime()+3)*20000); 464 usleep((_pppdata->modemEscapeGuardTime()+3)*20000);
465 465
466 data_mode = false; 466 data_mode = false;
467} 467}
468 468
469 469
470const QString Modem::modemMessage() { 470const QString Modem::modemMessage() {
471 return errmsg; 471 return errmsg;
472} 472}
473 473
474 474
475QString Modem::parseModemSpeed(const QString &s) { 475QString Modem::parseModemSpeed(const QString &s) {
476 // this is a small (and bad) parser for modem speeds 476 // this is a small (and bad) parser for modem speeds
477 int rx = -1; 477 int rx = -1;
478 int tx = -1; 478 int tx = -1;
479 int i; 479 int i;
480 QString result; 480 QString result;
481 481
482 odebug << "Modem reported result string: " << s.latin1() << "" << oendl; 482 odebug << "Modem reported result string: " << s.latin1() << "" << oendl;
483 483
484 const int RXMAX = 7; 484 const int RXMAX = 7;
485 const int TXMAX = 2; 485 const int TXMAX = 2;
486 QRegExp rrx[RXMAX] = { 486 QRegExp rrx[RXMAX] = {
487 QRegExp("[0-9]+[:/ ]RX", false), 487 QRegExp("[0-9]+[:/ ]RX", false),
488 QRegExp("[0-9]+RX", false), 488 QRegExp("[0-9]+RX", false),
489 QRegExp("[/: -][0-9]+[/: ]", false), 489 QRegExp("[/: -][0-9]+[/: ]", false),
490 QRegExp("[/: -][0-9]+$", false), 490 QRegExp("[/: -][0-9]+$", false),
491 QRegExp("CARRIER [^0-9]*[0-9]+", false), 491 QRegExp("CARRIER [^0-9]*[0-9]+", false),
492 QRegExp("CONNECT [^0-9]*[0-9]+", false), 492 QRegExp("CONNECT [^0-9]*[0-9]+", false),
493 QRegExp("[0-9]+") // panic mode 493 QRegExp("[0-9]+") // panic mode
494 }; 494 };
495 495
496 QRegExp trx[TXMAX] = { 496 QRegExp trx[TXMAX] = {
497 QRegExp("[0-9]+[:/ ]TX", false), 497 QRegExp("[0-9]+[:/ ]TX", false),
498 QRegExp("[0-9]+TX", false) 498 QRegExp("[0-9]+TX", false)
499 }; 499 };
500 500
501 for(i = 0; i < RXMAX; i++) { 501 for(i = 0; i < RXMAX; i++) {
502 int len, idx, result; 502 int len, idx, result;
503 if((idx = rrx[i].match(s,0,&len)) > -1) { 503 if((idx = rrx[i].match(s,0,&len)) > -1) {
504// if((idx = rrx[i].search(s)) > -1) { 504// if((idx = rrx[i].search(s)) > -1) {
505 // len = rrx[i].matchedLength(); 505 // len = rrx[i].matchedLength();
506 506
507 // 507 //
508 // rrx[i] has been matched, idx contains the start of the match 508 // rrx[i] has been matched, idx contains the start of the match
509 // and len contains how long the match is. Extract the match. 509 // and len contains how long the match is. Extract the match.
510 // 510 //
511 QString sub = s.mid(idx, len); 511 QString sub = s.mid(idx, len);
512 512
513 // 513 //
514 // Now extract the digits only from the match, which will 514 // Now extract the digits only from the match, which will
515 // then be converted to an int. 515 // then be converted to an int.
516 // 516 //
517 if ((idx = rrx[RXMAX-1].match( sub,0,&len )) > -1) { 517 if ((idx = rrx[RXMAX-1].match( sub,0,&len )) > -1) {
518// if ((idx = rrx[RXMAX-1].search( sub )) > -1) { 518// if ((idx = rrx[RXMAX-1].search( sub )) > -1) {
519// len = rrx[RXMAX-1].matchedLength(); 519// len = rrx[RXMAX-1].matchedLength();
520 sub = sub.mid(idx, len); 520 sub = sub.mid(idx, len);
521 result = sub.toInt(); 521 result = sub.toInt();
522 if(result > 0) { 522 if(result > 0) {
523 rx = result; 523 rx = result;
524 break; 524 break;
525 } 525 }
526 } 526 }
527 } 527 }
528 } 528 }
529 529
530 for(i = 0; i < TXMAX; i++) { 530 for(i = 0; i < TXMAX; i++) {
531 int len, idx, result; 531 int len, idx, result;
532 if((idx = trx[i].match(s,0,&len)) > -1) { 532 if((idx = trx[i].match(s,0,&len)) > -1) {
533// if((idx = trx[i].search(s)) > -1) { 533// if((idx = trx[i].search(s)) > -1) {
534// len = trx[i].matchedLength(); 534// len = trx[i].matchedLength();
535 535
536 // 536 //
537 // trx[i] has been matched, idx contains the start of the match 537 // trx[i] has been matched, idx contains the start of the match
538 // and len contains how long the match is. Extract the match. 538 // and len contains how long the match is. Extract the match.
539 // 539 //
540 QString sub = s.mid(idx, len); 540 QString sub = s.mid(idx, len);
541 541
542 // 542 //
543 // Now extract the digits only from the match, which will then 543 // Now extract the digits only from the match, which will then
544 // be converted to an int. 544 // be converted to an int.
545 // 545 //
546 if((idx = rrx[RXMAX-1].match(sub,0,&len)) > -1) { 546 if((idx = rrx[RXMAX-1].match(sub,0,&len)) > -1) {
547// if((idx = rrx[RXMAX-1].search(sub)) > -1) { 547// if((idx = rrx[RXMAX-1].search(sub)) > -1) {
548// len = rrx[RXMAX-1].matchedLength(); 548// len = rrx[RXMAX-1].matchedLength();
549 sub = sub.mid(idx, len); 549 sub = sub.mid(idx, len);
550 result = sub.toInt(); 550 result = sub.toInt();
551 if(result > 0) { 551 if(result > 0) {
552 tx = result; 552 tx = result;
553 break; 553 break;
554 } 554 }
555 } 555 }
556 } 556 }
557 } 557 }
558 558
559 if(rx == -1 && tx == -1) 559 if(rx == -1 && tx == -1)
560 result = QObject::tr("Unknown speed"); 560 result = QObject::tr("Unknown speed");
561 else if(tx == -1) 561 else if(tx == -1)
562 result.setNum(rx); 562 result.setNum(rx);
563 else if(rx == -1) // should not happen 563 else if(rx == -1) // should not happen
564 result.setNum(tx); 564 result.setNum(tx);
565 else 565 else
566 result.sprintf("%d/%d", rx, tx); 566 result.sprintf("%d/%d", rx, tx);
567 567
568 odebug << "The parsed result is: " << result.latin1() << "" << oendl; 568 odebug << "The parsed result is: " << result.latin1() << "" << oendl;
569 569
570 return result; 570 return result;
571} 571}
572 572
573 573
574// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if 574// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
575// a lock file can't be created ( permission problem ) 575// a lock file can't be created ( permission problem )
576int Modem::lockdevice() { 576int Modem::lockdevice() {
577 int fd; 577 int fd;
578 char newlock[80]=""; // safe 578 char newlock[80]=""; // safe
579 579
580 if(!_pppdata->modemLockFile()) { 580 if(!_pppdata->modemLockFile()) {
581 odebug << "The user doesn't want a lockfile." << oendl; 581 odebug << "The user doesn't want a lockfile." << oendl;
582 return 0; 582 return 0;
583 } 583 }
584 584
585 if (modem_is_locked) 585 if (modem_is_locked)
586 return 1; 586 return 1;
587 587
588 QString lockfile = LOCK_DIR"/LCK.."; 588 QString lockfile = LOCK_DIR"/LCK..";
589 lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/ 589 lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/
590 590
591 if(access(QFile::encodeName(lockfile), F_OK) == 0) { 591 if(access(QFile::encodeName(lockfile), F_OK) == 0) {
592// if ((fd = Requester::rq-> 592// if ((fd = Requester::rq->
593if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { 593if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
594 // Mario: it's not necessary to read more than lets say 32 bytes. If 594 // Mario: it's not necessary to read more than lets say 32 bytes. If
595 // file has more than 32 bytes, skip the rest 595 // file has more than 32 bytes, skip the rest
596 char oldlock[33]; // safe 596 char oldlock[33]; // safe
597 int sz = read(fd, &oldlock, 32); 597 int sz = read(fd, &oldlock, 32);
598 close (fd); 598 close (fd);
599 if (sz <= 0) 599 if (sz <= 0)
600 return 1; 600 return 1;
601 oldlock[sz] = '\0'; 601 oldlock[sz] = '\0';
602 602
603 odebug << "Device is locked by: " << oldlock << "" << oendl; 603 odebug << "Device is locked by: " << oldlock << "" << oendl;
604 604
605 int oldpid; 605 int oldpid;
606 int match = sscanf(oldlock, "%d", &oldpid); 606 int match = sscanf(oldlock, "%d", &oldpid);
607 607
608 // found a pid in lockfile ? 608 // found a pid in lockfile ?
609 if (match < 1 || oldpid <= 0) 609 if (match < 1 || oldpid <= 0)
610 return 1; 610 return 1;
611 611
612 // check if process exists 612 // check if process exists
613 if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) 613 if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH)
614 return 1; 614 return 1;
615 615
616 odebug << "lockfile is stale" << oendl; 616 odebug << "lockfile is stale" << oendl;
617 } 617 }
618 } 618 }
619 619
620 fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); 620 fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
621 if(fd >= 0) { 621 if(fd >= 0) {
622 sprintf(newlock,"%010d\n", getpid()); 622 sprintf(newlock,"%010d\n", getpid());
623 odebug << "Locking Device: " << newlock << "" << oendl; 623 odebug << "Locking Device: " << newlock << "" << oendl;
624 624
625 write(fd, newlock, strlen(newlock)); 625 write(fd, newlock, strlen(newlock));
626 close(fd); 626 close(fd);
627 modem_is_locked=true; 627 modem_is_locked=true;
628 628
629 return 0; 629 return 0;
630 } 630 }
631 631
632 return -1; 632 return -1;
633 633
634} 634}
635 635
636 636
637// UnLock modem device 637// UnLock modem device
638void Modem::unlockdevice() { 638void Modem::unlockdevice() {
639 if (modem_is_locked) { 639 if (modem_is_locked) {
640 odebug << "UnLocking Modem Device" << oendl; 640 odebug << "UnLocking Modem Device" << oendl;
641 close(modemfd); 641 close(modemfd);
642 modemfd = -1; 642 modemfd = -1;
643 unlink(lockfile); 643 unlink(lockfile);
644 lockfile[0] = '\0'; 644 lockfile[0] = '\0';
645 modem_is_locked=false; 645 modem_is_locked=false;
646 } 646 }
647} 647}
648 648
649int Modem::openLockfile( QString lockfile, int flags) 649int Modem::openLockfile( QString lockfile, int flags)
650{ 650{
651 int fd; 651 int fd;
652 int mode; 652 int mode;
653 flags = O_RDONLY; 653 flags = O_RDONLY;
654 if(flags == O_WRONLY|O_TRUNC|O_CREAT) 654 if(flags == O_WRONLY|O_TRUNC|O_CREAT)
655 mode = 0644; 655 mode = 0644;
656 else 656 else
657 mode = 0; 657 mode = 0;
658 658
659 lockfile = LOCK_DIR; 659 lockfile = LOCK_DIR;
660 lockfile += "/LCK.."; 660 lockfile += "/LCK..";
661 lockfile += device.right( device.length() - device.findRev("/") -1 ); 661 lockfile += device.right( device.length() - device.findRev("/") -1 );
662 odebug << "lockfile >" << lockfile.latin1() << "<" << oendl; 662 odebug << "lockfile >" << lockfile.latin1() << "<" << oendl;
663 // TODO: 663 // TODO:
664 // struct stat st; 664 // struct stat st;
665 // if(stat(lockfile.data(), &st) == -1) { 665 // if(stat(lockfile.data(), &st) == -1) {
666 // if(errno == EBADF) 666 // if(errno == EBADF)
667 // return -1; 667 // return -1;
668 // } else { 668 // } else {
669 // // make sure that this is a regular file 669 // // make sure that this is a regular file
670 // if(!S_ISREG(st.st_mode)) 670 // if(!S_ISREG(st.st_mode))
671 // return -1; 671 // return -1;
672 // } 672 // }
673 if ((fd = open(lockfile, flags, mode)) == -1) { 673 if ((fd = open(lockfile, flags, mode)) == -1) {
674 odebug << "error opening lockfile!" << oendl; 674 odebug << "error opening lockfile!" << oendl;
675 lockfile = QString::null; 675 lockfile = QString::null;
676 fd = open(DEVNULL, O_RDONLY); 676 fd = open(DEVNULL, O_RDONLY);
677 } else 677 } else
678 fchown(fd, 0, 0); 678 fchown(fd, 0, 0);
679 return fd; 679 return fd;
680} 680}
681 681
682 682
683 683
684void alarm_handler(int) { 684void alarm_handler(int) {
685 // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); 685 // fprintf(stderr, "alarm_handler(): Received SIGALRM\n");
686 686
687 // jump 687 // jump
688 siglongjmp(jmp_buffer, 1); 688 siglongjmp(jmp_buffer, 1);
689} 689}
690 690
691 691
692const char* Modem::authFile(Auth method, int version) { 692const char* Modem::authFile(Auth method, int version) {
693 switch(method|version) { 693 switch(method|version) {
694 case PAP|Original: 694 case PAP|Original:
695 return PAP_AUTH_FILE; 695 return PAP_AUTH_FILE;
696 break; 696 break;
697 case PAP|New: 697 case PAP|New:
698 return PAP_AUTH_FILE".new"; 698 return PAP_AUTH_FILE".new";
699 break; 699 break;
700 case PAP|Old: 700 case PAP|Old:
701 return PAP_AUTH_FILE".old"; 701 return PAP_AUTH_FILE".old";
702 break; 702 break;
703 case CHAP|Original: 703 case CHAP|Original:
704 return CHAP_AUTH_FILE; 704 return CHAP_AUTH_FILE;
705 break; 705 break;
706 case CHAP|New: 706 case CHAP|New:
707 return CHAP_AUTH_FILE".new"; 707 return CHAP_AUTH_FILE".new";
708 break; 708 break;
709 case CHAP|Old: 709 case CHAP|Old:
710 return CHAP_AUTH_FILE".old"; 710 return CHAP_AUTH_FILE".old";
711 break; 711 break;
712 default: 712 default:
713 return 0L; 713 return 0L;
714 } 714 }
715} 715}
716 716
717 717
718bool Modem::createAuthFile(Auth method, const char *username, const char *password) { 718bool Modem::createAuthFile(Auth method, const char *username, const char *password) {
719 const char *authfile, *oldName, *newName; 719 const char *authfile, *oldName, *newName;
720 char line[100]; 720 char line[100];
721 char regexp[2*MaxStrLen+30]; 721 char regexp[2*MaxStrLen+30];
722 regex_t preg; 722 regex_t preg;
723 723
724 if(!(authfile = authFile(method))) 724 if(!(authfile = authFile(method)))
725 return false; 725 return false;
726 726
727 if(!(newName = authFile(method, New))) 727 if(!(newName = authFile(method, New)))
728 return false; 728 return false;
729 729
730 // look for username, "username" or 'username' 730 // look for username, "username" or 'username'
731 // if you modify this RE you have to adapt regexp's size above 731 // if you modify this RE you have to adapt regexp's size above
732 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", 732 snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']",
733 username,username); 733 username,username);
734 MY_ASSERT(regcomp(&preg, regexp, 0) == 0); 734 MY_ASSERT(regcomp(&preg, regexp, 0) == 0);
735 735
736 // copy to new file pap- or chap-secrets 736 // copy to new file pap- or chap-secrets
737 int old_umask = umask(0077); 737 int old_umask = umask(0077);
738 FILE *fout = fopen(newName, "w"); 738 FILE *fout = fopen(newName, "w");
739 if(fout) { 739 if(fout) {
740 // copy old file 740 // copy old file
741 FILE *fin = fopen(authfile, "r"); 741 FILE *fin = fopen(authfile, "r");
742 if(fin) { 742 if(fin) {
743 while(fgets(line, sizeof(line), fin)) { 743 while(fgets(line, sizeof(line), fin)) {
744 if(regexec(&preg, line, 0, 0L, 0) == 0) 744 if(regexec(&preg, line, 0, 0L, 0) == 0)
745 continue; 745 continue;
746 fputs(line, fout); 746 fputs(line, fout);
747 } 747 }
748 fclose(fin); 748 fclose(fin);
749 } 749 }
750 750
751 // append user/pass pair 751 // append user/pass pair
752 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); 752 fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password);
753 fclose(fout); 753 fclose(fout);
754 } 754 }
755 755
756 // restore umask 756 // restore umask
757 umask(old_umask); 757 umask(old_umask);
758 758
759 // free memory allocated by regcomp 759 // free memory allocated by regcomp
760 regfree(&preg); 760 regfree(&preg);
761 761
762 if(!(oldName = authFile(method, Old))) 762 if(!(oldName = authFile(method, Old)))
763 return false; 763 return false;
764 764
765 // delete old file if any 765 // delete old file if any
766 unlink(oldName); 766 unlink(oldName);
767 767
768 rename(authfile, oldName); 768 rename(authfile, oldName);
769 rename(newName, authfile); 769 rename(newName, authfile);
770 770
771 return true; 771 return true;
772} 772}
773 773
774 774
775bool Modem::removeAuthFile(Auth method) { 775bool Modem::removeAuthFile(Auth method) {
776 const char *authfile, *oldName; 776 const char *authfile, *oldName;
777 777
778 if(!(authfile = authFile(method))) 778 if(!(authfile = authFile(method)))
779 return false; 779 return false;
780 if(!(oldName = authFile(method, Old))) 780 if(!(oldName = authFile(method, Old)))
781 return false; 781 return false;
782 782
783 if(access(oldName, F_OK) == 0) { 783 if(access(oldName, F_OK) == 0) {
784 unlink(authfile); 784 unlink(authfile);
785 return (rename(oldName, authfile) == 0); 785 return (rename(oldName, authfile) == 0);
786 } else 786 } else
787 return false; 787 return false;
788} 788}
789 789
790 790
791bool Modem::setSecret(int method, const char* name, const char* password) 791bool Modem::setSecret(int method, const char* name, const char* password)
792{ 792{
793 793
794 Auth auth; 794 Auth auth;
795 if(method == AUTH_PAPCHAP) 795 if(method == AUTH_PAPCHAP)
796 return setSecret(AUTH_PAP, name, password) && 796 return setSecret(AUTH_PAP, name, password) &&
797 setSecret(AUTH_CHAP, name, password); 797 setSecret(AUTH_CHAP, name, password);
798 798
799 switch(method) { 799 switch(method) {
800 case AUTH_PAP: 800 case AUTH_PAP:
801 auth = Modem::PAP; 801 auth = Modem::PAP;
802 break; 802 break;
803 case AUTH_CHAP: 803 case AUTH_CHAP:
804 auth = Modem::CHAP; 804 auth = Modem::CHAP;
805 break; 805 break;
806 default: 806 default:
807 return false; 807 return false;
808 } 808 }
809 809
810 return createAuthFile(auth, name, password); 810 return createAuthFile(auth, name, password);
811 811
812} 812}
813 813
814bool Modem::removeSecret(int method) 814bool Modem::removeSecret(int method)
815{ 815{
816 Auth auth; 816 Auth auth;
817 817
818 switch(method) { 818 switch(method) {
819 case AUTH_PAP: 819 case AUTH_PAP:
820 auth = Modem::PAP; 820 auth = Modem::PAP;
821 break; 821 break;
822 case AUTH_CHAP: 822 case AUTH_CHAP:
823 auth = Modem::CHAP; 823 auth = Modem::CHAP;
824 break; 824 break;
825 default: 825 default:
826 return false; 826 return false;
827 } 827 }
828 return removeAuthFile( auth ); 828 return removeAuthFile( auth );
829} 829}
830 830
831int checkForInterface() 831int checkForInterface()
832{ 832{
833// I don't know if Linux needs more initialization to get the ioctl to 833// I don't know if Linux needs more initialization to get the ioctl to
834// work, pppd seems to hint it does. But BSD doesn't, and the following 834// work, pppd seems to hint it does. But BSD doesn't, and the following
835// code should compile. 835// code should compile.
836#if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) 836#if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__)
837 int s, ok; 837 int s, ok;
838 struct ifreq ifr; 838 struct ifreq ifr;
839 // extern char *no_ppp_msg; 839 // extern char *no_ppp_msg;
840 840
841 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 841 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
842 return 1; /* can't tell */ 842 return 1; /* can't tell */
843 843
844 strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); 844 strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
845 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; 845 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
846 close(s); 846 close(s);
847 847
848 if (ok == -1) { 848 if (ok == -1) {
849// This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports 849// This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports
850// KLDs, the old LKM interface couldn't handle loading devices 850// KLDs, the old LKM interface couldn't handle loading devices
851// dynamically, and thus can't load ppp support on the fly 851// dynamically, and thus can't load ppp support on the fly
852#ifdef __FreeBSD__ 852#ifdef __FreeBSD__
853 // If we failed to load ppp support and don't have it already. 853 // If we failed to load ppp support and don't have it already.
854 if (kldload("if_ppp") == -1) { 854 if (kldload("if_ppp") == -1) {
855 return -1; 855 return -1;
856 } 856 }
857 return 0; 857 return 0;
858#else 858#else
859 return -1; 859 return -1;
860#endif 860#endif
861 } 861 }
862 return 0; 862 return 0;
863#else 863#else
864// We attempt to use the SunOS/SysVr4 method and stat /dev/ppp 864// We attempt to use the SunOS/SysVr4 method and stat /dev/ppp
865 struct stat buf; 865 struct stat buf;
866 866
867 memset(&buf, 0, sizeof(buf)); 867 memset(&buf, 0, sizeof(buf));
868 return stat("/dev/ppp", &buf); 868 return stat("/dev/ppp", &buf);
869#endif 869#endif
870} 870}
871 871
872bool Modem::execpppd(const char *arguments) { 872bool Modem::execpppd(const char *arguments) {
873 char buf[MAX_CMDLEN]; 873 char buf[MAX_CMDLEN];
874 char *args[MaxArgs]; 874 char *args[MaxArgs];
875 pid_t pgrpid; 875 pid_t pgrpid;
876 876
877 if(modemfd<0) 877 if(modemfd<0)
878 return false; 878 return false;
879 879
880 _pppdExitStatus = -1; 880 _pppdExitStatus = -1;
881 881
882 (void)::pipe( m_pppdLOG ); 882 (void)::pipe( m_pppdLOG );
883 883
884 switch(pppdPid = fork()) 884 switch(pppdPid = fork())
885 { 885 {
886 case -1: 886 case -1:
887 fprintf(stderr,"In parent: fork() failed\n"); 887 fprintf(stderr,"In parent: fork() failed\n");
888 ::close( m_pppdLOG[0] ); 888 ::close( m_pppdLOG[0] );
889 ::close( m_pppdLOG[1] ); 889 ::close( m_pppdLOG[1] );
890 return false; 890 return false;
891 break; 891 break;
892 892
893 case 0: 893 case 0:
894 // let's parse the arguments the user supplied into UNIX suitable form 894 // let's parse the arguments the user supplied into UNIX suitable form
895 // that is a list of pointers each pointing to exactly one word 895 // that is a list of pointers each pointing to exactly one word
896 strlcpy(buf, arguments); 896 strlcpy(buf, arguments);
897 parseargs(buf, args); 897 parseargs(buf, args);
898 // become a session leader and let /dev/ttySx 898 // become a session leader and let /dev/ttySx
899 // be the controlling terminal. 899 // be the controlling terminal.
900 pgrpid = setsid(); 900 pgrpid = setsid();
901#ifdef TIOCSCTTY 901#ifdef TIOCSCTTY
902 if(ioctl(modemfd, TIOCSCTTY, 0)<0) 902 if(ioctl(modemfd, TIOCSCTTY, 0)<0)
903 fprintf(stderr, "ioctl() failed.\n"); 903 fprintf(stderr, "ioctl() failed.\n");
904#elif defined (TIOCSPGRP) 904#elif defined (TIOCSPGRP)
905 if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) 905 if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0)
906 fprintf(stderr, "ioctl() failed.\n"); 906 fprintf(stderr, "ioctl() failed.\n");
907#endif 907#endif
908 if(tcsetpgrp(modemfd, pgrpid)<0) 908 if(tcsetpgrp(modemfd, pgrpid)<0)
909 fprintf(stderr, "tcsetpgrp() failed.\n"); 909 fprintf(stderr, "tcsetpgrp() failed.\n");
910 910
911 ::close( m_pppdLOG[0] ); 911 ::close( m_pppdLOG[0] );
912 ::setenv( "LANG", "C", 1 ); // overwrite 912 ::setenv( "LANG", "C", 1 ); // overwrite
913 dup2(m_pppdLOG[1], 11 ); // for logfd 11 913 dup2(m_pppdLOG[1], 11 ); // for logfd 11
914 dup2(modemfd, 0); 914 dup2(modemfd, 0);
915 dup2(modemfd, 1); 915 dup2(modemfd, 1);
916 916
917 917
918 switch (checkForInterface()) { 918 switch (checkForInterface()) {
919 case 1: 919 case 1:
920 fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); 920 fprintf(stderr, "Cannot determine if kernel supports ppp.\n");
921 break; 921 break;
922 case -1: 922 case -1:
923 fprintf(stderr, "Kernel does not support ppp, oops.\n"); 923 fprintf(stderr, "Kernel does not support ppp, oops.\n");
924 break; 924 break;
925 case 0: 925 case 0:
926 fprintf(stderr, "Kernel supports ppp alright.\n"); 926 fprintf(stderr, "Kernel supports ppp alright.\n");
927 break; 927 break;
928 } 928 }
929 929
930 execve(pppdPath(), args, 0L); 930 execve(pppdPath(), args, 0L);
931 _exit(0); 931 _exit(0);
932 break; 932 break;
933 933
934 default: 934 default:
935 odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl; 935 odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl;
936 close(modemfd); 936 close(modemfd);
937 937
938 ::close( m_pppdLOG[1] ); 938 ::close( m_pppdLOG[1] );
939 // set it to nonblocking io 939 // set it to nonblocking io
940 int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); 940 int flag = ::fcntl( m_pppdLOG[0], F_GETFL );
941 941
942 if ( !(flag & O_NONBLOCK) ) { 942 if ( !(flag & O_NONBLOCK) ) {
943 odebug << "Setting nonblocking io" << oendl; 943 odebug << "Setting nonblocking io" << oendl;
944 flag |= O_NONBLOCK; 944 flag |= O_NONBLOCK;
945 ::fcntl(m_pppdLOG[0], F_SETFL, flag ); 945 ::fcntl(m_pppdLOG[0], F_SETFL, flag );
946 } 946 }
947 947
948 delete m_modemDebug; 948 delete m_modemDebug;
949 m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this ); 949 m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this );
950 connect(m_modemDebug, SIGNAL(activated(int) ), 950 connect(m_modemDebug, SIGNAL(activated(int) ),
951 this, SLOT(slotModemDebug(int) ) ); 951 this, SLOT(slotModemDebug(int) ) );
952 952
953 modemfd = -1; 953 modemfd = -1;
954 m_pppdDev = QString::fromLatin1("ppp0"); 954 m_pppdDev = QString::fromLatin1("ppp0");
955 return true; 955 return true;
956 break; 956 break;
957 } 957 }
958} 958}
959 959
960 960
961bool Modem::killpppd() { 961bool Modem::killpppd() {
962 odebug << "In killpppd and pid is " << pppdPid << "" << oendl; 962 odebug << "In killpppd and pid is " << pppdPid << "" << oendl;
963 if(pppdPid > 0) { 963 if(pppdPid > 0) {
964 delete m_modemDebug; 964 delete m_modemDebug;
965 m_modemDebug = 0; 965 m_modemDebug = 0;
966 odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl; 966 odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl;
967 if(kill(pppdPid, SIGTERM) < 0) { 967 if(kill(pppdPid, SIGTERM) < 0) {
968 odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl; 968 odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl;
969 if(kill(pppdPid, SIGKILL) < 0) { 969 if(kill(pppdPid, SIGKILL) < 0) {
970 odebug << "Error killing " << pppdPid << "\n" << oendl; 970 odebug << "Error killing " << pppdPid << "\n" << oendl;
971 return false; 971 return false;
972 } 972 }
973 } 973 }
974 } 974 }
975 return true; 975 return true;
976} 976}
977 977
978 978
979void Modem::parseargs(char* buf, char** args) { 979void Modem::parseargs(char* buf, char** args) {
980 int nargs = 0; 980 int nargs = 0;
981 int quotes; 981 int quotes;
982 982
983 while(nargs < MaxArgs-1 && *buf != '\0') { 983 while(nargs < MaxArgs-1 && *buf != '\0') {
984 984
985 quotes = 0; 985 quotes = 0;
986 986
987 // Strip whitespace. Use nulls, so that the previous argument is 987 // Strip whitespace. Use nulls, so that the previous argument is
988 // terminated automatically. 988 // terminated automatically.
989 989
990 while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) ) 990 while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) )
991 *buf++ = '\0'; 991 *buf++ = '\0';
992 992
993 // detect begin of quoted argument 993 // detect begin of quoted argument
994 if (*buf == '"' || *buf == '\'') { 994 if (*buf == '"' || *buf == '\'') {
995 quotes = *buf; 995 quotes = *buf;
996 *buf++ = '\0'; 996 *buf++ = '\0';
997 } 997 }
998 998
999 // save the argument 999 // save the argument
1000 if(*buf != '\0') { 1000 if(*buf != '\0') {
1001 *args++ = buf; 1001 *args++ = buf;
1002 nargs++; 1002 nargs++;
1003 } 1003 }
1004 1004
1005 if (!quotes) 1005 if (!quotes)
1006 while ((*buf != '\0') && (*buf != '\n') && 1006 while ((*buf != '\0') && (*buf != '\n') &&
1007 (*buf != '\t') && (*buf != ' ')) 1007 (*buf != '\t') && (*buf != ' '))
1008 buf++; 1008 buf++;
1009 else { 1009 else {
1010 while ((*buf != '\0') && (*buf != quotes)) 1010 while ((*buf != '\0') && (*buf != quotes))
1011 buf++; 1011 buf++;
1012 *buf++ = '\0'; 1012 *buf++ = '\0';
1013 } 1013 }
1014 } 1014 }
1015 1015
1016 *args = 0L; 1016 *args = 0L;
1017} 1017}
1018 1018
1019bool Modem::execPPPDaemon(const QString & arguments) 1019bool Modem::execPPPDaemon(const QString & arguments)
1020{ 1020{
1021 if(execpppd(arguments)) { 1021 if(execpppd(arguments)) {
1022 _pppdata->setpppdRunning(true); 1022 _pppdata->setpppdRunning(true);
1023 return true; 1023 return true;
1024 } else 1024 } else
1025 return false; 1025 return false;
1026} 1026}
1027 1027
1028void Modem::killPPPDaemon() 1028void Modem::killPPPDaemon()
1029{ 1029{
1030 _pppdata->setpppdRunning(false); 1030 _pppdata->setpppdRunning(false);
1031 killpppd(); 1031 killpppd();
1032} 1032}
1033 1033
1034int Modem::pppdExitStatus() 1034int Modem::pppdExitStatus()
1035{ 1035{
1036 return _pppdExitStatus; 1036 return _pppdExitStatus;
1037} 1037}
1038 1038
1039int Modem::openResolv(int flags) 1039int Modem::openResolv(int flags)
1040{ 1040{
1041 int fd; 1041 int fd;
1042 if ((fd = open(_PATH_RESCONF, flags)) == -1) { 1042 if ((fd = open(_PATH_RESCONF, flags)) == -1) {
1043 odebug << "error opening resolv.conf!" << oendl; 1043 odebug << "error opening resolv.conf!" << oendl;
1044 fd = open(DEVNULL, O_RDONLY); 1044 fd = open(DEVNULL, O_RDONLY);
1045 } 1045 }
1046 return fd; 1046 return fd;
1047} 1047}
1048 1048
1049bool Modem::setHostname(const QString & name) 1049bool Modem::setHostname(const QString & name)
1050{ 1050{
1051 return sethostname(name, name.length()) == 0; 1051 return sethostname(name, name.length()) == 0;
1052} 1052}
1053 1053
1054QString Modem::pppDevice()const { 1054QString Modem::pppDevice()const {
1055 return m_pppdDev; 1055 return m_pppdDev;
1056} 1056}
1057void Modem::setPPPDevice( const QString& dev ) { 1057void Modem::setPPPDevice( const QString& dev ) {
1058 m_pppdDev = dev; 1058 m_pppdDev = dev;
1059} 1059}
1060pid_t Modem::pppPID()const { 1060pid_t Modem::pppPID()const {
1061 return pppdPid; 1061 return pppdPid;
1062} 1062}
1063void Modem::setPPPDPid( pid_t pid ) { 1063void Modem::setPPPDPid( pid_t pid ) {
1064 odebug << "Modem setting pid" << oendl; 1064 odebug << "Modem setting pid" << oendl;
1065 _pppdExitStatus = -1; 1065 _pppdExitStatus = -1;
1066 pppdPid = pid; 1066 pppdPid = pid;
1067 modemfd = -1; 1067 modemfd = -1;
1068} 1068}
1069void Modem::slotModemDebug(int fd) { 1069void Modem::slotModemDebug(int fd) {
1070 char buf[2049]; 1070 char buf[2049];
1071 int len; 1071 int len;
1072 1072
1073 // read in pppd data look for Using interface 1073 // read in pppd data look for Using interface
1074 // then read the interface 1074 // then read the interface
1075 // we limit to 10 device now 0-9 1075 // we limit to 10 device now 0-9
1076 if((len = ::read(fd, buf, 2048)) > 0) { 1076 if((len = ::read(fd, buf, 2048)) > 0) {
1077 buf[len+1] = '\0'; 1077 buf[len+1] = '\0';
1078 char *found; 1078 char *found;
1079 if ( (found = ::strstr(buf, "Using interface ") ) ) { 1079 if ( (found = ::strstr(buf, "Using interface ") ) ) {
1080 found += 16; 1080 found += 16;
1081 m_pppdDev = QString::fromLatin1(found, 5 ); 1081 m_pppdDev = QString::fromLatin1(found, 5 );
1082 m_pppdDev = m_pppdDev.simplifyWhiteSpace(); 1082 m_pppdDev = m_pppdDev.simplifyWhiteSpace();
1083 } 1083 }
1084 } 1084 }
1085} 1085}
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index 4294b12..d36a702 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -1,494 +1,493 @@
1#include "wlanimp2.h" 1#include "wlanimp2.h"
2#include "keyedit.h" 2#include "keyedit.h"
3#include "interfacesetupimp.h" 3#include "interfacesetupimp.h"
4#include "../interfaces/interface.h" 4#include "../interfaces/interface.h"
5 5
6#include <assert.h> 6#include <assert.h>
7#include <errno.h> 7#include <errno.h>
8#include <string.h> 8#include <string.h>
9 9
10/* OPIE */ 10/* OPIE */
11#include <opie2/odebug.h> 11#include <opie2/odebug.h>
12#include <opie2/oprocess.h> 12#include <opie2/oprocess.h>
13#include <opie2/onetwork.h> 13#include <opie2/onetwork.h>
14#include <opie2/opcap.h> 14#include <opie2/opcap.h>
15#include <qpe/resource.h> 15#include <qpe/resource.h>
16using namespace Opie::Core; 16using namespace Opie::Core;
17using namespace Opie::Net; 17using namespace Opie::Net;
18 18
19/* QT */ 19/* QT */
20#include <qapplication.h> 20#include <qapplication.h>
21#include <qfile.h> 21#include <qfile.h>
22#include <qdir.h> 22#include <qdir.h>
23#include <qdialog.h> 23#include <qdialog.h>
24#include <qtextstream.h> 24#include <qtextstream.h>
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26#include <qlineedit.h> 26#include <qlineedit.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qspinbox.h> 28#include <qspinbox.h>
29#include <qradiobutton.h> 29#include <qradiobutton.h>
30#include <qpushbutton.h> 30#include <qpushbutton.h>
31#include <qcheckbox.h> 31#include <qcheckbox.h>
32#include <qtabwidget.h> 32#include <qtabwidget.h>
33#include <qcombobox.h> 33#include <qcombobox.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qvbox.h> 35#include <qvbox.h>
36#include <qprogressbar.h> 36#include <qprogressbar.h>
37 37
38/* STD */ 38/* STD */
39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <string.h> 41#include <string.h>
42 42
43#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 43#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
44#define PREUP "/etc/network/if-pre-up.d/wireless-tools" 44#define PREUP "/etc/network/if-pre-up.d/wireless-tools"
45 45
46/** 46/**
47 * Constructor, read in the wireless.opts file for parsing later. 47 * Constructor, read in the wireless.opts file for parsing later.
48 */ 48 */
49WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { 49WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") {
50 interfaces = new Interfaces(); 50 interfaces = new Interfaces();
51 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); 51 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces);
52 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 52 tabWidget->insertTab(interfaceSetup, "TCP/IP");
53 53
54 // Check sanity - the existance of the wireless-tools if-pre-up script 54 // Check sanity - the existance of the wireless-tools if-pre-up script
55 QFile file(QString(PREUP)); 55 QFile file(QString(PREUP));
56 if (file.exists()) { 56 if (file.exists()) {
57 owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl; 57 owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl;
58 } 58 }
59 59
60 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); 60 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) );
61 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); 61 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) );
62 netView->setColumnAlignment( col_chn, AlignCenter ); 62 netView->setColumnAlignment( col_chn, AlignCenter );
63 netView->setItemMargin( 3 ); 63 netView->setItemMargin( 3 );
64 netView->setAllColumnsShowFocus( true ); 64 netView->setAllColumnsShowFocus( true );
65 65
66} 66}
67 67
68WLANImp::~WLANImp() { 68WLANImp::~WLANImp() {
69//FIXME: delete interfaces; 69//FIXME: delete interfaces;
70} 70}
71 71
72/** 72/**
73 * Change the profile for both wireless settings and network settings. 73 * Change the profile for both wireless settings and network settings.
74 */ 74 */
75void WLANImp::setProfile(const QString &profile){ 75void WLANImp::setProfile(const QString &profile){
76 interfaceSetup->setProfile(profile); 76 interfaceSetup->setProfile(profile);
77 parseOpts(); 77 parseOpts();
78} 78}
79 79
80void WLANImp::parseOpts() { 80void WLANImp::parseOpts() {
81 bool error; 81 bool error;
82 QString opt; 82 QString opt;
83 83
84 if (! interfaces->isInterfaceSet()) 84 if (! interfaces->isInterfaceSet())
85 return; 85 return;
86 86
87 87
88 opt = interfaces->getInterfaceOption("wireless_essid", error); 88 opt = interfaces->getInterfaceOption("wireless_essid", error);
89 if(opt == "any" || opt == "off" || opt.isNull()){ 89 if(opt == "any" || opt == "off" || opt.isNull()){
90 essid->setEditText("any"); 90 essid->setEditText("any");
91 } else { 91 } else {
92 essid->setEditText(opt); 92 essid->setEditText(opt);
93 } 93 }
94 94
95 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); 95 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace();
96 96
97 for ( int i = 0; i < mode->count(); i++) 97 for ( int i = 0; i < mode->count(); i++)
98 if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); 98 if ( mode->text( i ) == opt ) mode->setCurrentItem( i );
99 99
100 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); 100 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace();
101 if (! opt.isNull()) { 101 if (! opt.isNull()) {
102 specifyAp->setChecked(true); 102 specifyAp->setChecked(true);
103 macEdit->setText(opt); 103 macEdit->setText(opt);
104 } 104 }
105 105
106 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); 106 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace();
107 if (! opt.isNull()) { 107 if (! opt.isNull()) {
108 specifyChan->setChecked(true); 108 specifyChan->setChecked(true);
109 networkChannel->setValue(opt.toInt()); 109 networkChannel->setValue(opt.toInt());
110 } 110 }
111 111
112 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); 112 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace();
113 if (opt.isNull()) 113 if (opt.isNull())
114 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); 114 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace();
115 parseKeyStr(opt); 115 parseKeyStr(opt);
116} 116}
117 117
118void WLANImp::parseKeyStr(QString keystr) { 118void WLANImp::parseKeyStr(QString keystr) {
119 int loc = 0; 119 int loc = 0;
120 int index = 1; 120 int index = 1;
121 QString key; 121 QString key;
122 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); 122 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr);
123 int enc = -1; // encryption state 123 int enc = -1; // encryption state
124 124
125 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { 125 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) {
126 if ((*it).left(3) == "off") { 126 if ((*it).left(3) == "off") {
127 // encryption disabled 127 // encryption disabled
128 enc = 0; 128 enc = 0;
129 } else if ((*it).left(2) == "on") { 129 } else if ((*it).left(2) == "on") {
130 // encryption enabled 130 // encryption enabled
131 enc = 1; 131 enc = 1;
132 } else if ((*it).left(4) == "open") { 132 } else if ((*it).left(4) == "open") {
133 // open mode, accept non encrypted packets 133 // open mode, accept non encrypted packets
134 acceptNonEnc->setChecked(true); 134 acceptNonEnc->setChecked(true);
135 } else if ((*it).left(10) == "restricted") { 135 } else if ((*it).left(10) == "restricted") {
136 // restricted mode, only accept encrypted packets 136 // restricted mode, only accept encrypted packets
137 rejectNonEnc->setChecked(true); 137 rejectNonEnc->setChecked(true);
138 } else if ((*it).left(3) == "key") { 138 } else if ((*it).left(3) == "key") {
139 // new set of options 139 // new set of options
140 } else if ((*it).left(1) == "[") { 140 } else if ((*it).left(1) == "[") {
141 index = (*it).mid(1, 1).toInt(); 141 index = (*it).mid(1, 1).toInt();
142 // switch current key to index 142 // switch current key to index
143 switch (index) { 143 switch (index) {
144 case 1: 144 case 1:
145 keyRadio0->setChecked(true); 145 keyRadio0->setChecked(true);
146 break; 146 break;
147 case 2: 147 case 2:
148 keyRadio1->setChecked(true); 148 keyRadio1->setChecked(true);
149 break; 149 break;
150 case 3: 150 case 3:
151 keyRadio2->setChecked(true); 151 keyRadio2->setChecked(true);
152 break; 152 break;
153 case 4: 153 case 4:
154 keyRadio3->setChecked(true); 154 keyRadio3->setChecked(true);
155 break; 155 break;
156 } 156 }
157 } else { 157 } else {
158 // key 158 // key
159 key = (*it); 159 key = (*it);
160 } 160 }
161 if (! key.isNull()) { 161 if (! key.isNull()) {
162 if (enc == -1) 162 if (enc == -1)
163 enc = 1; 163 enc = 1;
164 QStringList::Iterator next = ++it; 164 QStringList::Iterator next = ++it;
165 if (it == keys.end()) { 165 if (it == keys.end()) {
166 break; 166 break;
167 } 167 }
168 if ((*(next)).left(1) == "[") { 168 if ((*(next)).left(1) == "[") {
169 // set key at index 169 // set key at index
170 index = (*(next)).mid(1, 1).toInt(); 170 index = (*(next)).mid(1, 1).toInt();
171 } else { 171 } else {
172 index = 1; 172 index = 1;
173 } 173 }
174 switch (index) { 174 switch (index) {
175 case 1: 175 case 1:
176 keyLineEdit0->setText(key); 176 keyLineEdit0->setText(key);
177 break; 177 break;
178 case 2: 178 case 2:
179 keyLineEdit1->setText(key); 179 keyLineEdit1->setText(key);
180 break; 180 break;
181 case 3: 181 case 3:
182 keyLineEdit2->setText(key); 182 keyLineEdit2->setText(key);
183 break; 183 break;
184 case 4: 184 case 4:
185 keyLineEdit3->setText(key); 185 keyLineEdit3->setText(key);
186 break; 186 break;
187 } 187 }
188 key = QString::null; 188 key = QString::null;
189 } 189 }
190 } 190 }
191 if (enc == 1) { 191 if (enc == 1) {
192 wepEnabled->setChecked(true); 192 wepEnabled->setChecked(true);
193 } else { 193 } else {
194 wepEnabled->setChecked(false); 194 wepEnabled->setChecked(false);
195 } 195 }
196} 196}
197 197
198/** 198/**
199 * Check to see if the current config is valid 199 * Check to see if the current config is valid
200 * Save interfaces 200 * Save interfaces
201 */ 201 */
202void WLANImp::accept() { 202void WLANImp::accept() {
203 if (wepEnabled->isChecked()) { 203 if (wepEnabled->isChecked()) {
204 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || 204 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) ||
205 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || 205 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) ||
206 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || 206 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) ||
207 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { 207 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) {
208 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); 208 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok);
209 return; 209 return;
210 } 210 }
211 } 211 }
212 212
213 if (essid->currentText().isEmpty()) { 213 if (essid->currentText().isEmpty()) {
214 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); 214 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
215 return; 215 return;
216 } 216 }
217 217
218 if (specifyAp->isChecked() && macEdit->text().isEmpty()) { 218 if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
219 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); 219 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
220 return; 220 return;
221 } 221 }
222 222
223 // Try to save the interfaces settings. 223 // Try to save the interfaces settings.
224 writeOpts(); 224 writeOpts();
225 225
226 // Close out the dialog 226 // Close out the dialog
227// FIXME: QDialog::accept(); 227// FIXME: QDialog::accept();
228} 228}
229 229
230void WLANImp::writeOpts() { 230void WLANImp::writeOpts() {
231 // eh can't really do anything about it other then return. :-D 231 // eh can't really do anything about it other then return. :-D
232 if(!interfaces->isInterfaceSet()){ 232 if(!interfaces->isInterfaceSet()){
233 QMessageBox::warning(0,"Inface not set","should not happen!!!"); 233 QMessageBox::warning(0,"Inface not set","should not happen!!!");
234 return; 234 return;
235 } 235 }
236 bool error = false; 236 bool error = false;
237 237
238 odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl; 238 odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl;
239 239
240 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); 240 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!");
241 241
242 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); 242 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText());
243 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); 243 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText());
244 244
245 if (specifyAp->isChecked()) { 245 if (specifyAp->isChecked()) {
246 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); 246 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text());
247 } else { 247 } else {
248 interfaces->removeInterfaceOption(QString("wireless_ap")); 248 interfaces->removeInterfaceOption(QString("wireless_ap"));
249 } 249 }
250 250
251 if (specifyChan->isChecked()) { 251 if (specifyChan->isChecked()) {
252 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); 252 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text());
253 } else { 253 } else {
254 interfaces->removeInterfaceOption(QString("wireless_channel")); 254 interfaces->removeInterfaceOption(QString("wireless_channel"));
255 } 255 }
256 256
257 if (wepEnabled->isChecked()) { 257 if (wepEnabled->isChecked()) {
258 QStringList keyList; 258 QStringList keyList;
259 259
260 if (! keyLineEdit0->text().isNull()) { 260 if (! keyLineEdit0->text().isNull()) {
261 keyList += keyLineEdit0->text(); 261 keyList += keyLineEdit0->text();
262 keyList += "[1]"; 262 keyList += "[1]";
263 } //else 263 } //else
264 if (! keyLineEdit1->text().isNull()) { 264 if (! keyLineEdit1->text().isNull()) {
265 keyList += keyLineEdit1->text(); 265 keyList += keyLineEdit1->text();
266 keyList += "[2]"; 266 keyList += "[2]";
267 } //else 267 } //else
268 if (! keyLineEdit2->text().isNull()) { 268 if (! keyLineEdit2->text().isNull()) {
269 keyList += keyLineEdit2->text(); 269 keyList += keyLineEdit2->text();
270 keyList += "[3]"; 270 keyList += "[3]";
271 } //else 271 } //else
272 if (! keyLineEdit3->text().isNull()) { 272 if (! keyLineEdit3->text().isNull()) {
273 keyList += keyLineEdit3->text(); 273 keyList += keyLineEdit3->text();
274 keyList += "[4]"; 274 keyList += "[4]";
275 } 275 }
276 if (acceptNonEnc->isChecked()) { 276 if (acceptNonEnc->isChecked()) {
277 keyList += "open"; 277 keyList += "open";
278 } else { 278 } else {
279 keyList += "restricted"; 279 keyList += "restricted";
280 } 280 }
281 281
282 keyList += "key"; 282 keyList += "key";
283 if (keyRadio0->isChecked()) { 283 if (keyRadio0->isChecked()) {
284 keyList += "[1]"; 284 keyList += "[1]";
285 } else if (keyRadio1->isChecked()) { 285 } else if (keyRadio1->isChecked()) {
286 keyList += "[2]"; 286 keyList += "[2]";
287 } else if (keyRadio2->isChecked()) { 287 } else if (keyRadio2->isChecked()) {
288 keyList += "[3]"; 288 keyList += "[3]";
289 } else if (keyRadio3->isChecked()) { 289 } else if (keyRadio3->isChecked()) {
290 keyList += "[4]"; 290 keyList += "[4]";
291 } 291 }
292 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); 292 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" ")));
293 } else { 293 } else {
294 interfaces->removeInterfaceOption(QString("wireless_key")); 294 interfaces->removeInterfaceOption(QString("wireless_key"));
295 } 295 }
296 interfaces->removeInterfaceOption(QString("wireless_enc")); 296 interfaces->removeInterfaceOption(QString("wireless_enc"));
297 297
298 if(!interfaceSetup->saveChanges()) 298 if(!interfaceSetup->saveChanges())
299 return; 299 return;
300 300
301 QDialog::accept(); 301 QDialog::accept();
302} 302}
303 303
304/* 304/*
305 * Scan for possible wireless networks around... 305 * Scan for possible wireless networks around...
306 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> 306 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org>
307 */ 307 */
308 308
309void WLANImp::rescanNeighbourhood() 309void WLANImp::rescanNeighbourhood()
310{ 310{
311 QString name = interface->getInterfaceName(); 311 QString name = interface->getInterfaceName();
312 odebug << "rescanNeighbourhood via '" << name << "'" << oendl; 312 odebug << "rescanNeighbourhood via '" << name << "'" << oendl;
313 313
314 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); 314 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) );
315 assert( wiface ); 315 assert( wiface );
316 316
317 // try to guess device type 317 // try to guess device type
318 QString devicetype; 318 QString devicetype;
319 QFile m( "/proc/modules" ); 319 QFile m( "/proc/modules" );
320 if ( m.open( IO_ReadOnly ) ) 320 if ( m.open( IO_ReadOnly ) )
321 { 321 {
322 QString line; 322 QString line;
323 QTextStream modules( &m ); 323 QTextStream modules( &m );
324 while( !modules.atEnd() && !devicetype ) 324 while( !modules.atEnd() && !devicetype )
325 { 325 {
326 modules >> line; 326 modules >> line;
327 if ( line.contains( "cisco" ) ) devicetype = "cisco"; 327 if ( line.contains( "cisco" ) ) devicetype = "cisco";
328 else if ( line.contains( "hostap" ) ) devicetype = "hostap"; 328 else if ( line.contains( "hostap" ) ) devicetype = "hostap";
329 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ 329 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */
330 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; 330 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco";
331 } 331 }
332 } 332 }
333 if ( devicetype.isEmpty() ) 333 if ( devicetype.isEmpty() )
334 { 334 {
335 owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl; 335 owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl;
336 return; 336 return;
337 } 337 }
338 else 338 else
339 { 339 {
340 odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl; 340 odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl;
341 } 341 }
342 342
343 // configure interface to receive 802.11 management frames 343 // configure interface to receive 802.11 management frames
344 344
345 wiface->setUp( true ); 345 wiface->setUp( true );
346 wiface->setPromiscuousMode( true ); 346 wiface->setPromiscuousMode( true );
347 347
348 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); 348 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) );
349 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); 349 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) );
350 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); 350 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) );
351 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); 351 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) );
352 else 352 else
353 { 353 {
354 odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl; 354 odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl;
355 return; 355 return;
356 } 356 }
357 357
358 wiface->setMode( "monitor" ); 358 wiface->setMode( "monitor" );
359 if ( wiface->mode() != "monitor" ) 359 if ( wiface->mode() != "monitor" )
360 { 360 {
361 owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl; 361 owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl;
362 return; 362 return;
363 } 363 }
364 364
365 // open a packet capturer 365 // open a packet capturer
366 OPacketCapturer* cap = new OPacketCapturer(); 366 OPacketCapturer* cap = new OPacketCapturer();
367 cap->open( name ); 367 cap->open( name );
368 if ( !cap->isOpen() ) 368 if ( !cap->isOpen() )
369 { 369 {
370 owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl; 370 owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl;
371 return; 371 return;
372 } 372 }
373 373
374 // display splash screen 374 // display splash screen
375 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); 375 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize );
376 splash->setLineWidth( 2 ); 376 splash->setLineWidth( 2 );
377 splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); 377 splash->setFrameStyle( QFrame::Panel | QFrame::Raised );
378 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); 378 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 );
379 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); 379 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash );
380 QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); 380 QProgressBar* pb = new QProgressBar( wiface->channels(), splash );
381 vbox->addWidget( lab ); 381 vbox->addWidget( lab );
382 vbox->addWidget( pb ); 382 vbox->addWidget( pb );
383 pb->setCenterIndicator( true ); 383 pb->setCenterIndicator( true );
384 pb->setFixedHeight( pb->sizeHint().height() ); 384 pb->setFixedHeight( pb->sizeHint().height() );
385 QWidget* widgetDesktop = qApp->desktop(); 385 QWidget* widgetDesktop = qApp->desktop();
386 int dw = widgetDesktop->width(); 386 int dw = widgetDesktop->width();
387 int dh = widgetDesktop->height(); 387 int dh = widgetDesktop->height();
388 int pw = vbox->sizeHint().width(); 388 int pw = vbox->sizeHint().width();
389 int ph = vbox->sizeHint().height(); 389 int ph = vbox->sizeHint().height();
390 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); 390 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph);
391 splash->show(); 391 splash->show();
392 splash->raise(); 392 splash->raise();
393 qApp->processEvents(); 393 qApp->processEvents();
394 394
395 // set capturer to non-blocking mode 395 // set capturer to non-blocking mode
396 cap->setBlocking( false ); 396 cap->setBlocking( false );
397 397
398 for ( int i = 1; i <= wiface->channels(); ++i ) 398 for ( int i = 1; i <= wiface->channels(); ++i )
399 { 399 {
400 wiface->setChannel( i ); 400 wiface->setChannel( i );
401 pb->setProgress( i ); 401 pb->setProgress( i );
402 qApp->processEvents(); 402 qApp->processEvents();
403 odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl; 403 odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl;
404 OPacket* p = cap->next( 1000 ); 404 OPacket* p = cap->next( 1000 );
405 if ( !p ) 405 if ( !p )
406 { 406 {
407 odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl; 407 odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl;
408 } 408 }
409 else 409 else
410 { 410 {
411 odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl; 411 odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl;
412 handlePacket( p ); 412 handlePacket( p );
413 } 413 }
414 } 414 }
415 415
416 cap->close(); 416 cap->close();
417 wiface->setMode( "managed" ); // TODO: use previous mode 417 wiface->setMode( "managed" ); // TODO: use previous mode
418 wiface->setPromiscuousMode( false ); 418 wiface->setPromiscuousMode( false );
419 419
420 splash->hide(); 420 splash->hide();
421 delete splash; 421 delete splash;
422 422
423} 423}
424 424
425void WLANImp::handlePacket( OPacket* p ) 425void WLANImp::handlePacket( OPacket* p )
426{ 426{
427 427
428 // check if we received a beacon frame 428 // check if we received a beacon frame
429 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); 429 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) );
430 if ( beacon && beacon->managementType() == "Beacon" ) 430 if ( beacon && beacon->managementType() == "Beacon" )
431 { 431 {
432 432
433 QString type; 433 QString type;
434 if ( beacon->canIBSS() ) 434 if ( beacon->canIBSS() )
435 { 435 {
436 type = "adhoc"; 436 type = "adhoc";
437 } 437 }
438 else if ( beacon->canESS() ) 438 else if ( beacon->canESS() )
439 { 439 {
440 type = "managed"; 440 type = "managed";
441 } 441 }
442 else 442 else
443 { 443 {
444 owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl; 444 owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl;
445 return; 445 return;
446 } 446 }
447 447
448 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 448 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
449 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 449 QString essid = ssid ? ssid->ID() : QString("<unknown>");
450 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 450 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
451 int channel = ds ? ds->channel() : -1; 451 int channel = ds ? ds->channel() : -1;
452 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 452 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
453 displayFoundNetwork( type, channel, essid, header->macAddress2() ); 453 displayFoundNetwork( type, channel, essid, header->macAddress2() );
454 } 454 }
455} 455}
456 456
457 457
458void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) 458void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac )
459{ 459{
460 460
461 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, 461 odebug << "found network: <" << (const char*) mode << ">, chn " << channel
462 (const char*) ssid, 462 << ", ssid '" << (const char*) ssid << "', mac '" << (const char*) mac.toString() << "'" << oendl;
463 (const char*) mac.toString() );
464 463
465 QListViewItemIterator it( netView ); 464 QListViewItemIterator it( netView );
466 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; 465 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it;
467 if ( !it.current() ) // ssid didn't show up yet 466 if ( !it.current() ) // ssid didn't show up yet
468 { 467 {
469 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); 468 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() );
470 QString name; 469 QString name;
471 name.sprintf( "networksettings/%s", (const char*) mode ); 470 name.sprintf( "networksettings/%s", (const char*) mode );
472 item->setPixmap( col_mode, Resource::loadPixmap( name ) ); 471 item->setPixmap( col_mode, Resource::loadPixmap( name ) );
473 qApp->processEvents(); 472 qApp->processEvents();
474 } 473 }
475 474
476} 475}
477 476
478 477
479void WLANImp::selectNetwork( QListViewItem* item ) 478void WLANImp::selectNetwork( QListViewItem* item )
480{ 479{
481 bool ok; 480 bool ok;
482 if ( item ) 481 if ( item )
483 { 482 {
484 specifyAp->setChecked(true); 483 specifyAp->setChecked(true);
485 macEdit->setText( item->text( col_mac ) ); 484 macEdit->setText( item->text( col_mac ) );
486 specifyChan->setChecked( item->text( col_mode ) == "A" ); 485 specifyChan->setChecked( item->text( col_mode ) == "A" );
487 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); 486 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) );
488 essid->setEditText( item->text( col_ssid ) ); 487 essid->setEditText( item->text( col_ssid ) );
489 if ( item->text( col_mode ) == "A" ) 488 if ( item->text( col_mode ) == "A" )
490 mode->setCurrentItem( 3 ); 489 mode->setCurrentItem( 3 );
491 else 490 else
492 mode->setCurrentItem( 2 ); 491 mode->setCurrentItem( 2 );
493 } 492 }
494} 493}