summaryrefslogtreecommitdiffstats
path: root/tdeio/tdefile/tdefilepreview.cpp
blob: 57543ea8cd06f59ad91a9f42ab553d925907ed63 (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
/* This file is part of the KDE libraries
    Copyright (C) 1998 Stephan Kulow <[email protected]>
                  1998 Daniel Grana <[email protected]>
                  2000 Werner Trobin <[email protected]>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <tdeaction.h>
#include <tdefilepreview.h>
#include <tdefilepreview.moc>
#include <klocale.h>

#include <tqlabel.h>

#include "config-tdefile.h"

KFilePreview::KFilePreview(KFileView *view, TQWidget *parent, const char *name)
    : TQSplitter(parent, name), KFileView()
{
    if ( view )
        init( view );
    else
        init( new KFileIconView( (TQSplitter*) this, "left" ));
}


KFilePreview::KFilePreview(TQWidget *parent, const char *name) :
                           TQSplitter(parent, name), KFileView()
{
    init( new KFileIconView((TQSplitter*)this, "left") );
}

KFilePreview::~KFilePreview()
{
    // Why copy the actions in the first place? --ellis, 13 Jan 02.
    //// don't delete the view's actions (inserted into our collection)!
    //for ( uint i = 0; i < left->actionCollection()->count(); i++ )
    //    actionCollection()->take( left->actionCollection()->action( i ));

    // don't delete the preview, we can reuse it
    // (it will get deleted by ~KDirOperator)
    if ( preview && preview->parentWidget() == this ) {
        preview->reparent(0L, 0, TQPoint(0, 0), false);
    }
}

void KFilePreview::init( KFileView *view )
{
    setViewName( i18n("Preview") );

    left = 0L;
    setFileView( view );

    preview = new TQWidget((TQSplitter*)this, "preview");
    TQString tmp = i18n("No preview available.");
    TQLabel *l = new TQLabel(tmp, preview);
    l->setMinimumSize(l->sizeHint());
    l->move(10, 5);
    preview->setMinimumWidth(l->sizeHint().width()+20);
    setResizeMode(preview, TQSplitter::KeepSize);

    // Why copy the actions? --ellis, 13 Jan 02.
    //for ( uint i = 0; i < view->actionCollection()->count(); i++ )
    //    actionCollection()->insert( view->actionCollection()->action( i ));
}

void KFilePreview::setFileView( KFileView *view )
{
    Q_ASSERT( view );

    // Why copy the actions? --ellis, 13 Jan 02.
    //if ( left ) { // remove any previous actions
    //    for ( uint i = 0; i < left->actionCollection()->count(); i++ )
    //        actionCollection()->take( left->actionCollection()->action( i ));
    //}

    delete left;
    view->widget()->reparent( this, TQPoint(0,0) );
    view->KFileView::setViewMode(All);
    view->setParentView(this);
    view->setSorting( sorting() );
    left = view;

    connect( left->signaler(), TQT_SIGNAL( fileHighlighted(const KFileItem*) ),
             TQT_SLOT( slotHighlighted( const KFileItem * )));

    // Why copy the actions? --ellis, 13 Jan 02.
    //for ( uint i = 0; i < view->actionCollection()->count(); i++ )
    //    actionCollection()->insert( view->actionCollection()->action( i ));
}

// this url parameter is useless... it's the url of the current directory.
// what for?
void KFilePreview::setPreviewWidget(const TQWidget *w, const KURL &)
{
    left->setOnlyDoubleClickSelectsFiles( onlyDoubleClickSelectsFiles() );

    if (w) {
        connect(this, TQT_SIGNAL( showPreview(const KURL &) ),
                w, TQT_SLOT( showPreview(const KURL &) ));
        connect( this, TQT_SIGNAL( clearPreview() ),
                w, TQT_SLOT( clearPreview() ));
    }
    else {
        preview->hide();
        return;
    }

    delete preview;
    preview = const_cast<TQWidget*>(w);
    preview->reparent((TQSplitter*)this, 0, TQPoint(0, 0), true);
    preview->resize(preview->sizeHint());
    preview->show();
}

void KFilePreview::insertItem(KFileItem *item)
{
    KFileView::insertItem( item );
    left->insertItem(item);
}

void KFilePreview::setSorting( TQDir::SortSpec sort )
{
    left->setSorting( sort );
    KFileView::setSorting( left->sorting() );
}

void KFilePreview::clearView()
{
    left->clearView();
    emit clearPreview();
}

void KFilePreview::updateView(bool b)
{
    left->updateView(b);
    if(preview)
        preview->repaint(b);
}

void KFilePreview::updateView(const KFileItem *i)
{
    left->updateView(i);
}

void KFilePreview::removeItem(const KFileItem *i)
{
    if ( left->isSelected( i ) )
        emit clearPreview();

    left->removeItem(i);
    KFileView::removeItem( i );
}

void KFilePreview::listingCompleted()
{
    left->listingCompleted();
}

void KFilePreview::clear()
{
    KFileView::clear();
    left->KFileView::clear();
}

void KFilePreview::clearSelection()
{
    left->clearSelection();
    emit clearPreview();
}

void KFilePreview::selectAll()
{
    left->selectAll();
}

void KFilePreview::invertSelection()
{
    left->invertSelection();
}

bool KFilePreview::isSelected( const KFileItem *i ) const
{
    return left->isSelected( i );
}

void KFilePreview::setSelectionMode(KFile::SelectionMode sm) {
    left->setSelectionMode( sm );
}

void KFilePreview::setSelected(const KFileItem *item, bool enable) {
    left->setSelected( item, enable );
}

void KFilePreview::setCurrentItem( const KFileItem *item )
{
    left->setCurrentItem( item );
}

KFileItem * KFilePreview::currentFileItem() const
{
    return left->currentFileItem();
}

void KFilePreview::slotHighlighted(const KFileItem* item)
{
    if ( item )
        emit showPreview( item->url() );

    else { // item = 0 -> multiselection mode
        const KFileItemList *items = selectedItems();
        if ( items->count() == 1 )
            emit showPreview( items->getFirst()->url() );
        else
            emit clearPreview();
    }

    // the preview widget appears and takes some space of the left view,
    // so we may have to scroll to make the current item visible
    left->ensureItemVisible(item);
 }

void KFilePreview::ensureItemVisible(const KFileItem *item)
{
    left->ensureItemVisible(item);
}

KFileItem * KFilePreview::firstFileItem() const
{
    return left->firstFileItem();
}

KFileItem * KFilePreview::nextItem( const KFileItem *item ) const
{
    return left->nextItem( item );
}

KFileItem * KFilePreview::prevItem( const KFileItem *item ) const
{
    return left->prevItem( item );
}

TDEActionCollection * KFilePreview::actionCollection() const
{
    if ( left )
        return left->actionCollection();
    else {
        kdWarning() << "KFilePreview::actionCollection(): called before setFileView()." << endl; //ellis
        return KFileView::actionCollection();
    }
}

void KFilePreview::readConfig( TDEConfig *config, const TQString& group )
{
    left->readConfig( config, group );
}

void KFilePreview::writeConfig( TDEConfig *config, const TQString& group )
{
    left->writeConfig( config, group );
}

void KFilePreview::virtual_hook( int id, void* data )
{ KFileView::virtual_hook( id, data ); }