summaryrefslogtreecommitdiffstats
path: root/examples/fileiconview/mainwindow.cpp
blob: d2d6f2edb113a177d6d122229de34c5a45d71c14 (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
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "mainwindow.h"
#include "qfileiconview.h"
#include "../dirview/dirview.h"

#include <ntqsplitter.h>
#include <ntqprogressbar.h>
#include <ntqlabel.h>
#include <ntqstatusbar.h>
#include <ntqtoolbar.h>
#include <ntqcombobox.h>
#include <ntqpixmap.h>
#include <ntqtoolbutton.h>
#include <ntqdir.h>
#include <ntqfileinfo.h>

static const char* cdtoparent_xpm[]={
    "15 13 3 1",
    ". c None",
    "* c #000000",
    "a c #ffff99",
    "..*****........",
    ".*aaaaa*.......",
    "***************",
    "*aaaaaaaaaaaaa*",
    "*aaaa*aaaaaaaa*",
    "*aaa***aaaaaaa*",
    "*aa*****aaaaaa*",
    "*aaaa*aaaaaaaa*",
    "*aaaa*aaaaaaaa*",
    "*aaaa******aaa*",
    "*aaaaaaaaaaaaa*",
    "*aaaaaaaaaaaaa*",
    "***************"};

static const char* newfolder_xpm[] = {
    "15 14 4 1",
    " 	c None",
    ".	c #000000",
    "+	c #FFFF00",
    "@	c #FFFFFF",
    "          .    ",
    "               ",
    "          .    ",
    "       .     . ",
    "  ....  . . .  ",
    " .+@+@.  . .   ",
    "..........  . .",
    ".@+@+@+@+@..   ",
    ".+@+@+@+@+. .  ",
    ".@+@+@+@+@.  . ",
    ".+@+@+@+@+.    ",
    ".@+@+@+@+@.    ",
    ".+@+@+@+@+.    ",
    "...........    "};

FileMainWindow::FileMainWindow()
    : TQMainWindow()
{
    setup();
}

void FileMainWindow::show()
{
    TQMainWindow::show();
}

void FileMainWindow::setup()
{
    TQSplitter *splitter = new TQSplitter( this );

    dirlist = new DirectoryView( splitter, "dirlist", TRUE );
    dirlist->addColumn( "Name" );
    dirlist->addColumn( "Type" );
    Directory *root = new Directory( dirlist, "/" );
    root->setOpen( TRUE );
    splitter->setResizeMode( dirlist, TQSplitter::KeepSize );

    fileview = new TQtFileIconView( "/", splitter );
    fileview->setSelectionMode( TQIconView::Extended );

    setCentralWidget( splitter );

    TQToolBar *toolbar = new TQToolBar( this, "toolbar" );
    setRightJustification( TRUE );

    (void)new TQLabel( tr( " Path: " ), toolbar );

    pathCombo = new TQComboBox( TRUE, toolbar );
    pathCombo->setAutoCompletion( TRUE );
    toolbar->setStretchableWidget( pathCombo );
    connect( pathCombo, TQ_SIGNAL( activated( const TQString & ) ),
	     this, TQ_SLOT ( changePath( const TQString & ) ) );

    toolbar->addSeparator();

    TQPixmap pix;

    pix = TQPixmap( cdtoparent_xpm );
    upButton = new TQToolButton( pix, "One directory up", TQString::null,
				this, TQ_SLOT( cdUp() ), toolbar, "cd up" );

    pix = TQPixmap( newfolder_xpm );
    mkdirButton = new TQToolButton( pix, "New Folder", TQString::null,
				   this, TQ_SLOT( newFolder() ), toolbar, "new folder" );

    connect( dirlist, TQ_SIGNAL( folderSelected( const TQString & ) ),
	     fileview, TQ_SLOT ( setDirectory( const TQString & ) ) );
    connect( fileview, TQ_SIGNAL( directoryChanged( const TQString & ) ),
	     this, TQ_SLOT( directoryChanged( const TQString & ) ) );
    connect( fileview, TQ_SIGNAL( startReadDir( int ) ),
	     this, TQ_SLOT( slotStartReadDir( int ) ) );
    connect( fileview, TQ_SIGNAL( readNextDir() ),
	     this, TQ_SLOT( slotReadNextDir() ) );
    connect( fileview, TQ_SIGNAL( readDirDone() ),
	     this, TQ_SLOT( slotReadDirDone() ) );

    setDockEnabled( DockLeft, FALSE );
    setDockEnabled( DockRight, FALSE );

    label = new TQLabel( statusBar() );
    statusBar()->addWidget( label, 2, TRUE );
    progress = new TQProgressBar( statusBar() );
    statusBar()->addWidget( progress, 1, TRUE );

    connect( fileview, TQ_SIGNAL( enableUp() ),
	     this, TQ_SLOT( enableUp() ) );
    connect( fileview, TQ_SIGNAL( disableUp() ),
	     this, TQ_SLOT( disableUp() ) );
    connect( fileview, TQ_SIGNAL( enableMkdir() ),
	     this, TQ_SLOT( enableMkdir() ) );
    connect( fileview, TQ_SIGNAL( disableMkdir() ),
	     this, TQ_SLOT( disableMkdir() ) );
}

void FileMainWindow::setPathCombo()
{
    TQString dir = caption();
    int i = 0;
    bool found = FALSE;
    for ( i = 0; i < pathCombo->count(); ++i ) {
	if ( pathCombo->text( i ) == dir) {
	    found = TRUE;
	    break;
	}
    }

    if ( found )
	pathCombo->setCurrentItem( i );
    else {
	pathCombo->insertItem( dir );
	pathCombo->setCurrentItem( pathCombo->count() - 1 );
    }

}

void FileMainWindow::directoryChanged( const TQString &dir )
{
    setCaption( dir );
    setPathCombo();
}

void FileMainWindow::slotStartReadDir( int dirs )
{
    label->setText( tr( " Reading Directory..." ) );
    progress->reset();
    progress->setTotalSteps( dirs );
}

void FileMainWindow::slotReadNextDir()
{
    int p = progress->progress();
    progress->setProgress( ++p );
}

void FileMainWindow::slotReadDirDone()
{
    label->setText( tr( " Reading Directory Done." ) );
    progress->setProgress( progress->totalSteps() );
}

void FileMainWindow::cdUp()
{
    TQDir dir = fileview->currentDir();
    dir.cd( ".." );
    fileview->setDirectory( dir );
}

void FileMainWindow::newFolder()
{
    fileview->newDirectory();
}

void FileMainWindow::changePath( const TQString &path )
{
    if ( TQFileInfo( path ).exists() )
	fileview->setDirectory( path );
    else
	setPathCombo();
}

void FileMainWindow::enableUp()
{
    upButton->setEnabled( TRUE );
}

void FileMainWindow::disableUp()
{
    upButton->setEnabled( FALSE );
}

void FileMainWindow::enableMkdir()
{
    mkdirButton->setEnabled( TRUE );
}

void FileMainWindow::disableMkdir()
{
    mkdirButton->setEnabled( FALSE );
}