summaryrefslogtreecommitdiffstats
path: root/krename/mydirplugin.cpp
blob: fd877ef015c9163c9556834924d82fdc95711dce (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
/***************************************************************************
                          mydirplugin.cpp  -  description
                             -------------------
    begin                : Tue Jan 29 2002
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

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

// Own includes
#include "mydirplugin.h"

// KDE includes
#include <tdeapplication.h>
#include <kiconloader.h>
#include <tdefiledialog.h>
#include <tdelocale.h>

// QT includes
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqgroupbox.h>
#include <tqspinbox.h>

const TQString MyDirPlugin::getName() const
{
    return i18n("Dir Plugin");
}

const TQString MyDirPlugin::getAccelName() const
{
    return i18n("&Dir Plugin");
}

const int MyDirPlugin::type() const
{
    return TYPE_FINAL_FILE;
}

bool MyDirPlugin::checkError()
{
    return true;
}

const TQPixmap MyDirPlugin::getIcon() const
{
    return kapp->iconLoader()->loadIcon( "folder", TDEIcon::Small );
}

void MyDirPlugin::drawInterface( TQWidget* w, TQVBoxLayout* l )
{
    TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    TQSpacerItem* spacer2 = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );

    TQVBoxLayout* LayoutA = new TQVBoxLayout( 0, 6, 6 );
    TQVBoxLayout* LayoutB = new TQVBoxLayout( 0, 6, 6 );

    m_widget = w;

    TQLabel* la = new TQLabel( w );
    la->setText( i18n("<qt>This plugin sorts files after renaming in subdirectories.</qt>") );
    l->addWidget( la );

    groupNumber = new TQGroupBox( w );
    groupNumber->setTitle( i18n( "&Options" ) );
    groupNumber->setColumnLayout(0, Qt::Vertical );
    groupNumber->layout()->setSpacing( 6 );
    groupNumber->layout()->setMargin( 11 );
    groupNumberLayout = new TQHBoxLayout( groupNumber->layout() );
    groupNumberLayout->setAlignment( TQt::AlignTop );

    TQLabel* la2 = new TQLabel( groupNumber );
    la2->setText( i18n( "Files per directory:" ) );

    spinFiles = new TQSpinBox( groupNumber );
    spinFiles->setRange( 1, 60000 );
    spinFiles->setValue( 10 );

    TQLabel* la3 = new TQLabel( groupNumber );
    la3->setText( i18n( "Start index:" ) );

    spinStart = new TQSpinBox( groupNumber );
    spinFiles->setRange( 0, 60000 );

    LayoutA->addWidget( la2 );
    LayoutA->addWidget( la3 );
    LayoutB->addWidget( spinFiles );
    LayoutB->addWidget( spinStart );

    groupNumberLayout->addLayout( LayoutA );
    groupNumberLayout->addLayout( LayoutB );
    groupNumberLayout->addItem( spacer );

    groupOutput = new TQGroupBox( w );
    groupOutput->setTitle( i18n( "Output &Directory" ) );
    groupOutput->setColumnLayout(0, Qt::Vertical );
    groupOutput->layout()->setSpacing( 6 );
    groupOutput->layout()->setMargin( 11 );
    groupOutputLayout = new TQHBoxLayout( groupOutput->layout() );
    groupOutputLayout->setAlignment( TQt::AlignTop );

    outputdir = new TQLineEdit( groupOutput );
    buttonDir = new TQPushButton( groupOutput );
    buttonDir->setText( "..." );

    groupOutputLayout->addWidget( outputdir );
    groupOutputLayout->addWidget( buttonDir );

    l->addWidget( groupNumber );
    l->addWidget( groupOutput );
    l->addItem( spacer2 );

    connect( buttonDir, TQT_SIGNAL(clicked()), this, TQT_SLOT(chooseDir()));
}

void MyDirPlugin::fillStructure()
{
    fpd = spinFiles->value();
    fpd--;
    dir = outputdir->text();

    filecounter = 0;
    dircounter = spinStart->value();
    curdir = dir +  TQString("/%1/").arg( dircounter );

    d = new TQDir( dir );
    d->mkdir( curdir );
}

TQString MyDirPlugin::processFile( BatchRenamer*, int, TQString token, int )
{
    TQString newname;
    // token = filename
    if( filecounter == fpd ) {
        filecounter = 0;
        dircounter++;
        curdir = dir +  TQString("/%1/").arg( dircounter );
        d->mkdir( curdir );
    }

    TQFileInfo f( token );
    newname = curdir + f.fileName();
    d->rename( token, newname );
    filecounter++;
    return TQString();
}

void MyDirPlugin::finished()
{
    filecounter = dircounter = 0;
}

void MyDirPlugin::chooseDir()
{
    TQString s (KFileDialog::getExistingDirectory ( TQString() ));
    if(!s.isEmpty())
        outputdir->setText( s );
}

#include "mydirplugin.moc"