| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: mainwindow.cpp 160 2006-12-11 20:15:57Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of an example program for Qt. This example
|
|---|
| 7 | ** program may be used, distributed and modified without limitation.
|
|---|
| 8 | **
|
|---|
| 9 | *****************************************************************************/
|
|---|
| 10 |
|
|---|
| 11 | #include "mainwindow.h"
|
|---|
| 12 | #include "qfileiconview.h"
|
|---|
| 13 | #include "../dirview/dirview.h"
|
|---|
| 14 |
|
|---|
| 15 | #include <qsplitter.h>
|
|---|
| 16 | #include <qprogressbar.h>
|
|---|
| 17 | #include <qlabel.h>
|
|---|
| 18 | #include <qstatusbar.h>
|
|---|
| 19 | #include <qtoolbar.h>
|
|---|
| 20 | #include <qcombobox.h>
|
|---|
| 21 | #include <qpixmap.h>
|
|---|
| 22 | #include <qtoolbutton.h>
|
|---|
| 23 | #include <qdir.h>
|
|---|
| 24 | #include <qfileinfo.h>
|
|---|
| 25 |
|
|---|
| 26 | static const char* cdtoparent_xpm[]={
|
|---|
| 27 | "15 13 3 1",
|
|---|
| 28 | ". c None",
|
|---|
| 29 | "* c #000000",
|
|---|
| 30 | "a c #ffff99",
|
|---|
| 31 | "..*****........",
|
|---|
| 32 | ".*aaaaa*.......",
|
|---|
| 33 | "***************",
|
|---|
| 34 | "*aaaaaaaaaaaaa*",
|
|---|
| 35 | "*aaaa*aaaaaaaa*",
|
|---|
| 36 | "*aaa***aaaaaaa*",
|
|---|
| 37 | "*aa*****aaaaaa*",
|
|---|
| 38 | "*aaaa*aaaaaaaa*",
|
|---|
| 39 | "*aaaa*aaaaaaaa*",
|
|---|
| 40 | "*aaaa******aaa*",
|
|---|
| 41 | "*aaaaaaaaaaaaa*",
|
|---|
| 42 | "*aaaaaaaaaaaaa*",
|
|---|
| 43 | "***************"};
|
|---|
| 44 |
|
|---|
| 45 | static const char* newfolder_xpm[] = {
|
|---|
| 46 | "15 14 4 1",
|
|---|
| 47 | " c None",
|
|---|
| 48 | ". c #000000",
|
|---|
| 49 | "+ c #FFFF00",
|
|---|
| 50 | "@ c #FFFFFF",
|
|---|
| 51 | " . ",
|
|---|
| 52 | " ",
|
|---|
| 53 | " . ",
|
|---|
| 54 | " . . ",
|
|---|
| 55 | " .... . . . ",
|
|---|
| 56 | " .+@+@. . . ",
|
|---|
| 57 | ".......... . .",
|
|---|
| 58 | ".@+@+@+@+@.. ",
|
|---|
| 59 | ".+@+@+@+@+. . ",
|
|---|
| 60 | ".@+@+@+@+@. . ",
|
|---|
| 61 | ".+@+@+@+@+. ",
|
|---|
| 62 | ".@+@+@+@+@. ",
|
|---|
| 63 | ".+@+@+@+@+. ",
|
|---|
| 64 | "........... "};
|
|---|
| 65 |
|
|---|
| 66 | FileMainWindow::FileMainWindow()
|
|---|
| 67 | : QMainWindow()
|
|---|
| 68 | {
|
|---|
| 69 | setup();
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void FileMainWindow::show()
|
|---|
| 73 | {
|
|---|
| 74 | QMainWindow::show();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void FileMainWindow::setup()
|
|---|
| 78 | {
|
|---|
| 79 | QSplitter *splitter = new QSplitter( this );
|
|---|
| 80 |
|
|---|
| 81 | dirlist = new DirectoryView( splitter, "dirlist", TRUE );
|
|---|
| 82 | dirlist->addColumn( "Name" );
|
|---|
| 83 | dirlist->addColumn( "Type" );
|
|---|
| 84 | Directory *root = new Directory( dirlist, "/" );
|
|---|
| 85 | root->setOpen( TRUE );
|
|---|
| 86 | splitter->setResizeMode( dirlist, QSplitter::KeepSize );
|
|---|
| 87 |
|
|---|
| 88 | fileview = new QtFileIconView( "/", splitter );
|
|---|
| 89 | fileview->setSelectionMode( QIconView::Extended );
|
|---|
| 90 |
|
|---|
| 91 | setCentralWidget( splitter );
|
|---|
| 92 |
|
|---|
| 93 | QToolBar *toolbar = new QToolBar( this, "toolbar" );
|
|---|
| 94 | setRightJustification( TRUE );
|
|---|
| 95 |
|
|---|
| 96 | (void)new QLabel( tr( " Path: " ), toolbar );
|
|---|
| 97 |
|
|---|
| 98 | pathCombo = new QComboBox( TRUE, toolbar );
|
|---|
| 99 | pathCombo->setAutoCompletion( TRUE );
|
|---|
| 100 | toolbar->setStretchableWidget( pathCombo );
|
|---|
| 101 | connect( pathCombo, SIGNAL( activated( const QString & ) ),
|
|---|
| 102 | this, SLOT ( changePath( const QString & ) ) );
|
|---|
| 103 |
|
|---|
| 104 | toolbar->addSeparator();
|
|---|
| 105 |
|
|---|
| 106 | QPixmap pix;
|
|---|
| 107 |
|
|---|
| 108 | pix = QPixmap( cdtoparent_xpm );
|
|---|
| 109 | upButton = new QToolButton( pix, "One directory up", QString::null,
|
|---|
| 110 | this, SLOT( cdUp() ), toolbar, "cd up" );
|
|---|
| 111 |
|
|---|
| 112 | pix = QPixmap( newfolder_xpm );
|
|---|
| 113 | mkdirButton = new QToolButton( pix, "New Folder", QString::null,
|
|---|
| 114 | this, SLOT( newFolder() ), toolbar, "new folder" );
|
|---|
| 115 |
|
|---|
| 116 | connect( dirlist, SIGNAL( folderSelected( const QString & ) ),
|
|---|
| 117 | fileview, SLOT ( setDirectory( const QString & ) ) );
|
|---|
| 118 | connect( fileview, SIGNAL( directoryChanged( const QString & ) ),
|
|---|
| 119 | this, SLOT( directoryChanged( const QString & ) ) );
|
|---|
| 120 | connect( fileview, SIGNAL( startReadDir( int ) ),
|
|---|
| 121 | this, SLOT( slotStartReadDir( int ) ) );
|
|---|
| 122 | connect( fileview, SIGNAL( readNextDir() ),
|
|---|
| 123 | this, SLOT( slotReadNextDir() ) );
|
|---|
| 124 | connect( fileview, SIGNAL( readDirDone() ),
|
|---|
| 125 | this, SLOT( slotReadDirDone() ) );
|
|---|
| 126 |
|
|---|
| 127 | setDockEnabled( DockLeft, FALSE );
|
|---|
| 128 | setDockEnabled( DockRight, FALSE );
|
|---|
| 129 |
|
|---|
| 130 | label = new QLabel( statusBar() );
|
|---|
| 131 | statusBar()->addWidget( label, 2, TRUE );
|
|---|
| 132 | progress = new QProgressBar( statusBar() );
|
|---|
| 133 | statusBar()->addWidget( progress, 1, TRUE );
|
|---|
| 134 |
|
|---|
| 135 | connect( fileview, SIGNAL( enableUp() ),
|
|---|
| 136 | this, SLOT( enableUp() ) );
|
|---|
| 137 | connect( fileview, SIGNAL( disableUp() ),
|
|---|
| 138 | this, SLOT( disableUp() ) );
|
|---|
| 139 | connect( fileview, SIGNAL( enableMkdir() ),
|
|---|
| 140 | this, SLOT( enableMkdir() ) );
|
|---|
| 141 | connect( fileview, SIGNAL( disableMkdir() ),
|
|---|
| 142 | this, SLOT( disableMkdir() ) );
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | void FileMainWindow::setPathCombo()
|
|---|
| 146 | {
|
|---|
| 147 | QString dir = caption();
|
|---|
| 148 | int i = 0;
|
|---|
| 149 | bool found = FALSE;
|
|---|
| 150 | for ( i = 0; i < pathCombo->count(); ++i ) {
|
|---|
| 151 | if ( pathCombo->text( i ) == dir) {
|
|---|
| 152 | found = TRUE;
|
|---|
| 153 | break;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | if ( found )
|
|---|
| 158 | pathCombo->setCurrentItem( i );
|
|---|
| 159 | else {
|
|---|
| 160 | pathCombo->insertItem( dir );
|
|---|
| 161 | pathCombo->setCurrentItem( pathCombo->count() - 1 );
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | void FileMainWindow::directoryChanged( const QString &dir )
|
|---|
| 167 | {
|
|---|
| 168 | setCaption( dir );
|
|---|
| 169 | setPathCombo();
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | void FileMainWindow::slotStartReadDir( int dirs )
|
|---|
| 173 | {
|
|---|
| 174 | label->setText( tr( " Reading Directory..." ) );
|
|---|
| 175 | progress->reset();
|
|---|
| 176 | progress->setTotalSteps( dirs );
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | void FileMainWindow::slotReadNextDir()
|
|---|
| 180 | {
|
|---|
| 181 | int p = progress->progress();
|
|---|
| 182 | progress->setProgress( ++p );
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | void FileMainWindow::slotReadDirDone()
|
|---|
| 186 | {
|
|---|
| 187 | label->setText( tr( " Reading Directory Done." ) );
|
|---|
| 188 | progress->setProgress( progress->totalSteps() );
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void FileMainWindow::cdUp()
|
|---|
| 192 | {
|
|---|
| 193 | QDir dir = fileview->currentDir();
|
|---|
| 194 | dir.cd( ".." );
|
|---|
| 195 | fileview->setDirectory( dir );
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | void FileMainWindow::newFolder()
|
|---|
| 199 | {
|
|---|
| 200 | fileview->newDirectory();
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | void FileMainWindow::changePath( const QString &path )
|
|---|
| 204 | {
|
|---|
| 205 | if ( QFileInfo( path ).exists() )
|
|---|
| 206 | fileview->setDirectory( path );
|
|---|
| 207 | else
|
|---|
| 208 | setPathCombo();
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | void FileMainWindow::enableUp()
|
|---|
| 212 | {
|
|---|
| 213 | upButton->setEnabled( TRUE );
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | void FileMainWindow::disableUp()
|
|---|
| 217 | {
|
|---|
| 218 | upButton->setEnabled( FALSE );
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | void FileMainWindow::enableMkdir()
|
|---|
| 222 | {
|
|---|
| 223 | mkdirButton->setEnabled( TRUE );
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | void FileMainWindow::disableMkdir()
|
|---|
| 227 | {
|
|---|
| 228 | mkdirButton->setEnabled( FALSE );
|
|---|
| 229 | }
|
|---|