summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/mainwindow.cpp
blob: 1c56aae7b7db221c22f5c063d4beb4346b240f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
// adadpted form qpe/qipkg


#include "mainwindow.h"

#include <qpe/qpemenubar.h>
#include <qpe/qpemessagebox.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpetoolbar.h>
#include <qpe/qcopenvelope_qws.h>
#include <qaction.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qtoolbutton.h>
#include <qstring.h>
#include <qlabel.h>
#include <qfile.h>
#include <qlistview.h>
#include <qtextview.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qtabwidget.h>
#include <qcombobox.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qlayout.h>

#include "pksettingsbase.h"
#include "utils.h"
#include "packagelistitem.h"


MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
  QMainWindow( parent, name, f )
{	
  setCaption( tr("Package Manager") );
  settings = new PackageManagerSettings(this,0,TRUE);
  listViewPackages =  new PackageListView( this,"listViewPackages",settings );
  setCentralWidget( listViewPackages );
  listViewPackages->addList( tr("feeds"), &packageListServers );
  listViewPackages->addList( tr("ipkgfind"), &packageListSearch );
  listViewPackages->addList( tr("documents"), &packageListDocLnk );
//	wait = new QMessageBox(tr("oipkg"),tr("Please wait")//,QMessageBox::Information,QMessageBox::NoButton,QMessageBox::NoButton,QMessageBox::NoButton);
//	wait = new QMessageBox(this);
// 	wait->setText(tr("Please wait"));
  ipkg = new PmIpkg( settings, this );
//  settings->setIpkg( ipkg );
  packageListServers.setSettings( settings );
  packageListSearch.setSettings( settings );
  packageListDocLnk.setSettings( settings );
	pvDebug(9,"packageListServers.update");
  packageListServers.update();
	pvDebug(9,"packageListDocLnk.update");
  packageListDocLnk.update();
	pvDebug(9,"makeMenu");
  makeMenu();	
  makeChannel();
  //opie is hardcoded default ;)
//	pvDebug(9,"section->setCurrentItem");
//  for (int i=0;i<section->count();i++)
//  	if (section->text(i)=="opie")
//   		section->setCurrentItem(i);
//  sectionChanged();

  connect( section,    SIGNAL(activated(int)), SLOT(sectionChanged()) );
  connect( subsection, SIGNAL(activated(int)), SLOT(subSectionChanged()) );

  connect( settings->removeLinksButton, SIGNAL( clicked()),
  					 SLOT(removeLinks()) );
  connect( settings->createLinksButton, SIGNAL( clicked()),
  					 SLOT(createLinks()) );

	pvDebug(9,"displayList");
  displayList();
}

void MainWindow::makeMenu()
{

  QPEToolBar *toolBar = new QPEToolBar( this );
  QPEMenuBar *menuBar = new QPEMenuBar( toolBar );
  QPopupMenu *srvMenu = new QPopupMenu( menuBar );
  QPopupMenu *viewMenu = new QPopupMenu( menuBar );
  QPopupMenu *cfgMenu = new QPopupMenu( menuBar );
  //    QPopupMenu *sectMenu = new QPopupMenu( menuBar );

  setToolBarsMovable( false );
  toolBar->setHorizontalStretchable( true );
  menuBar->insertItem( tr( "Package" ), srvMenu );
  menuBar->insertItem( tr( "View" ), viewMenu );
  menuBar->insertItem( tr( "Settings" ), cfgMenu );
  //    menuBar->insertItem( tr( "Sections" ), sectMenu );

  QLabel *spacer;
//  spacer = new QLabel( "", toolBar );
//  spacer->setBackgroundColor( toolBar->backgroundColor() );
//  toolBar->setStretchableWidget( spacer );

		
  runAction = new QAction( tr( "Apply" ),
			   Resource::loadPixmap( "oipkg/install" ),
			   QString::null, 0, this, 0 );
  connect( runAction, SIGNAL( activated() ),
	   this, SLOT( runIpkg() ) );
  runAction->addTo( toolBar );
  runAction->addTo( srvMenu );

  srvMenu->insertSeparator ();

  updateAction = new QAction( tr( "Update" ),
			      Resource::loadIconSet( "oipkg/update" ),
			      QString::null, 0, this, 0 );
  connect( updateAction, SIGNAL( activated() ),
	   this , SLOT( updateList() ) );
  updateAction->addTo( toolBar );
  updateAction->addTo( srvMenu );

  QAction *cfgact;

  cfgact = new QAction( tr( "Setups" ),
			QString::null, 0, this, 0 );
  connect( cfgact, SIGNAL( activated() ),
	   SLOT( showSettings() ) );
  cfgact->addTo( cfgMenu );
		
  cfgact = new QAction( tr( "Servers" ),
			QString::null, 0, this, 0 );
  connect( cfgact, SIGNAL( activated() ),
	   SLOT( showSettingsSrv() ) );
  cfgact->addTo( cfgMenu );
  cfgact = new QAction( tr( "Destinations" ),
			QString::null, 0, this, 0 );
  connect( cfgact, SIGNAL( activated() ),
	   SLOT( showSettingsDst() ) );
  cfgact->addTo( cfgMenu );

  QAction *a;

  // SECTIONS
	sectionBar = new QPEToolBar( this );
 	addToolBar( sectionBar,  "Section", QMainWindow::Top, TRUE );
  sectionBar->setHorizontalStretchable( true );
  QLabel *label = new QLabel( tr("Section: "), sectionBar );
  label->setBackgroundColor( sectionBar->backgroundColor() );
 	sectionBar->setStretchableWidget( label );
  section = new QComboBox( false, sectionBar );
  label = new QLabel( " / ", sectionBar );
  label->setBackgroundColor( sectionBar->backgroundColor() );
  subsection = new QComboBox( false, sectionBar );
  a = new QAction( tr( "Close Section" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), this, SLOT( sectionClose() ) );
  a->addTo( sectionBar );
  setSections();
  setSubSections();
  sectionAction = new QAction( tr( "Sections" ), QString::null, 0, this, 0 );
  connect( sectionAction, SIGNAL( toggled(bool) ), this, SLOT( sectionShow(bool) ) );
  sectionAction->setToggleAction( true );
  sectionAction->addTo( viewMenu );

  //FIND
  findBar = new QPEToolBar(this);
  addToolBar( findBar,  "Filter", QMainWindow::Top, TRUE );
  label = new QLabel( tr("Filter: "), findBar );
  label->setBackgroundColor( findBar->backgroundColor() );
  findBar->setHorizontalStretchable( TRUE );
  findEdit = new QLineEdit( findBar, "findEdit" );
  findBar->setStretchableWidget( findEdit );
  connect( findEdit, SIGNAL( textChanged( const QString & ) ),
       this, SLOT( displayList() ) );
  a = new QAction( tr( "Clear Find" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), findEdit, SLOT( clear() ) );
  a->addTo( findBar );
  a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
  a->addTo( findBar );
  findAction = new QAction( tr( "Filter" ), QString::null, 0, this, 0 );
  connect( findAction, SIGNAL( toggled(bool) ), this, SLOT( findShow(bool) ) );
  findAction->setToggleAction( true );
  findAction->addTo( viewMenu );

  //SEARCH
  searchBar = new QPEToolBar(this);
  addToolBar( searchBar,  "Search", QMainWindow::Top, TRUE );
  label = new QLabel( tr("ipkgfind: "), searchBar );
  label->setBackgroundColor( searchBar->backgroundColor() );
  searchBar->setHorizontalStretchable( TRUE );
  searchEdit = new QLineEdit( searchBar, "seachEdit" );
  searchBar->setStretchableWidget( searchEdit );
//  connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
//       this, SLOT( displayList() ) );
  a = new QAction( tr( "Clear Search" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), searchEdit, SLOT( clear() ) );
  a->addTo( searchBar );
  searchCommit  = new QAction( tr( "Do Search" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
  connect( searchCommit, SIGNAL( activated() ),  SLOT( remotePackageQuery() ) );
  searchCommit->addTo( searchBar );
  a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), this, SLOT( searchClose() ) );
  a->addTo( searchBar );
  searchAction = new QAction( tr( "Search" ), QString::null, 0, this, 0 );
  connect( searchAction, SIGNAL( toggled(bool) ), this, SLOT( searchShow(bool) ) );
  searchAction->setToggleAction( true );
  searchAction->addTo( viewMenu );

  //DEST
  destBar = new QPEToolBar(this);
  addToolBar( destBar,  "Destination", QMainWindow::Top, TRUE );
  label = new QLabel( tr("Destination: "), destBar );
  label->setBackgroundColor( destBar->backgroundColor() );
  destBar->setHorizontalStretchable( TRUE );
  destination = new QComboBox( false, destBar );
  destination->insertStringList( settings->getDestinationNames() );
  setComboName(destination,settings->getDestinationName());
  connect( destination, SIGNAL(activated(int)),
  			 settings, SLOT(activeDestinationChange(int)) );
  spacer = new QLabel( " ", destBar );
  spacer->setBackgroundColor( destBar->backgroundColor() );
  CheckBoxLink = new QCheckBox( tr("Link"), destBar);
  CheckBoxLink->setBackgroundColor( destBar->backgroundColor() );
  CheckBoxLink->setChecked( settings->createLinks() );
  connect( CheckBoxLink, SIGNAL(toggled(bool)),
     				 settings, SLOT(linkEnabled(bool)) );
  destAction = new QAction( tr( "Destinations" ), QString::null, 0, this, 0 );
  connect( destAction, SIGNAL( toggled(bool) ), SLOT( destShow(bool) ) );
  a = new QAction( tr( "Close Destinations" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
  connect( a, SIGNAL( activated() ), SLOT( destClose() ) );
  a->addTo( destBar );
  destBar->setStretchableWidget( CheckBoxLink );
  destAction->setToggleAction( true );
 // destAction->addTo( viewMenu );

  // configure the menus
  Config cfg( "oipkg", Config::User );
  cfg.setGroup( "gui" );

  findShow( cfg.readBoolEntry( "findBar", true ) );
  searchShow( cfg.readBoolEntry( "searchBar", true ) );
  sectionShow( cfg.readBoolEntry( "sectionBar", true ) );
  destShow( cfg.readBoolEntry( "destBar", false ) );
}

MainWindow::~MainWindow()
{
  Config cfg( "oipkg", Config::User );
  cfg.setGroup( "gui" );
  cfg.writeEntry( "findBar", !findBar->isHidden() );
  cfg.writeEntry( "searchBar", !searchBar->isHidden() );
  cfg.writeEntry( "sectionBar", !sectionBar->isHidden() );
  cfg.writeEntry( "destBar", !destBar->isHidden() );
	
}

void MainWindow::runIpkg()
{
  packageListServers.allPackages();
  ipkg->loadList( &packageListSearch );
  ipkg->loadList( &packageListDocLnk );
  ipkg->loadList( &packageListServers );
  ipkg->commit();
  ipkg->clearLists();
  // ##### If we looked in the list of files, we could send out accurate
  // ##### messages. But we don't bother yet, and just do an "all".
  QCopEnvelope e("QPE/System", "linkChanged(QString)");
  QString lf = QString::null;
  e << lf;
  displayList();
}

void MainWindow::updateList()
{
//	wait->show();
	QTimer *t = new QTimer( this );
  connect( t, SIGNAL(timeout()), SLOT( rotateUpdateIcon() ) );
  t->start( 0, false );
	packageListServers.clear();
	packageListSearch.clear();
  packageListDocLnk.clear();
  ipkg->update();
  packageListServers.update();
  packageListSearch.update();
  packageListDocLnk.update();
  t->stop();
//	wait->hide();  	
}

void MainWindow::filterList()
{
//	wait->show();
 	QString f = "";
  if ( findAction->isOn() ) f = findEdit->text();
  packageListServers.filterPackages( f );
//	wait->hide();
}

void MainWindow::displayList()
{
//	wait->hide();
	filterList();
  listViewPackages->display();
}

void MainWindow::sectionChanged()
{
  disconnect( section, SIGNAL( activated(int) ),
	      this, SLOT( sectionChanged() ) );
  disconnect( subsection, SIGNAL(activated(int) ),
	      this, SLOT( subSectionChanged() ) );
  subsection->clear();
  packageListServers.setSection( section->currentText() );
  setSubSections();
  connect( section, SIGNAL( activated(int) ),
	   this, SLOT( sectionChanged() ) );
  connect( subsection, SIGNAL(activated(int) ),
	   this, SLOT( subSectionChanged() ) );
  displayList();
}

void MainWindow::subSectionChanged()
{
  disconnect( section, SIGNAL( activated(int) ),
	      this, SLOT( sectionChanged() ) );
  disconnect( subsection, SIGNAL(activated(int) ),
	      this, SLOT( subSectionChanged() ) );
  packageListServers.setSubSection( subsection->currentText() );
  connect( section, SIGNAL( activated(int) ),
	   this, SLOT( sectionChanged() ) );
  connect( subsection, SIGNAL(activated(int) ),
	   this, SLOT( subSectionChanged() ) );
  displayList();
}

void MainWindow::setSections()
{
  section->clear();
  section->insertStringList( packageListServers.getSections() );
}

void MainWindow::setSubSections()
{
  subsection->clear();
  subsection->insertStringList( packageListServers.getSubSections() );
}


void MainWindow::showSettings()
{
  if ( settings->showDialog( 0 ) )
    updateList();
}
void MainWindow::showSettingsSrv()
{
  if ( settings->showDialog( 1 ) )
    updateList();
}
void MainWindow::showSettingsDst()
{
  if ( settings->showDialog( 2 ) )
    updateList();
}

void MainWindow::sectionShow(bool b)
{
	if (b) sectionBar->show();
  else sectionBar->hide();
  sectionAction->setOn( b );
}

void MainWindow::sectionClose()
{
  sectionAction->setOn( false );
}

void MainWindow::findShow(bool b)
{
	if (b) findBar->show();
  else findBar->hide();
  findAction->setOn( b );
}

void MainWindow::findClose()
{
  findAction->setOn( false );
}

void MainWindow::searchShow(bool b)
{
	if (b) searchBar->show();
  else searchBar->hide();
  searchAction->setOn( b );
}

void MainWindow::searchClose()
{
  searchAction->setOn( false );
}


void MainWindow::destShow(bool b)
{
	if (b) destBar->show();
  else destBar->hide();
  destAction->setOn( b );
}

void MainWindow::destClose()
{
  destAction->setOn( false );
}

void MainWindow::rotateUpdateIcon()
{
	pvDebug(2, "MainWindow::rotateUpdateIcon");
 if ( updateIcon )
	updateAction->setIconSet( Resource::loadIconSet( "oipkg/update" ) );
 else
	updateAction->setIconSet( Resource::loadIconSet( "oipkg/update2" ) );
 updateIcon = !updateIcon;
}


void MainWindow::setDocument(const QString &fileName)
{
 	if ( !QFile::exists( fileName ) ) return;
	ipkg->installFile( fileName );
  QCopEnvelope e("QPE/System", "linkChanged(QString)");
  QString lf = QString::null;
  e << lf;
 	exit;
}


void MainWindow::makeChannel()
{   	
	channel = new QCopChannel( "QPE/Application/oipkg", this );
	connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
		this, SLOT(receive(const QCString&, const QByteArray&)) );
}



void MainWindow::receive(const QCString &msg, const QByteArray &arg)
{
	pvDebug(3, "QCop "+msg+" "+QCString(arg));
	if ( msg == "installFile(QString)" )
 	{
  	ipkg->installFile( QString(arg) );
	}else if( msg == "removeFile(QString)" )
 	{
  	ipkg->removeFile( QString(arg) );
	}else if( msg == "createLinks(QString)" )
 	{
  	ipkg->createLinks( QString(arg) );
	}else if( msg == "removeLinks(QString)" )
 	{
  	ipkg->removeLinks( QString(arg) );
	}else{
    	pvDebug(2,"Huh what do ya want")
 	}
}


void MainWindow::createLinks()
{
	pvDebug(2,"creating links...");
	ipkg->createLinks( settings->destinationurl->text() );
}

void MainWindow::removeLinks()
{
	pvDebug(2,"removing links...");
	ipkg->removeLinks( settings->destinationurl->text() );
}

void MainWindow::remotePackageQuery()
{
 	packageListSearch.query( searchEdit->text() );
  packageListSearch.update();
 	displayList();
}