summaryrefslogtreecommitdiffstats
path: root/krusader/Splitter/splittergui.cpp
blob: 2c575bcffbb8a0bdf1232abb743fc642a721084e (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
/***************************************************************************
                        splittergui.cpp  -  description
                             -------------------
    copyright            : (C) 2003 by Csaba Karai
    e-mail               : krusader@users.sourceforge.net
    web site             : http://krusader.sourceforge.net
 ---------------------------------------------------------------------------
  Description
 ***************************************************************************

  A

     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.
     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D
     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'
     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b
     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.
     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD

                                                     S o u r c e    F i l e

 ***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "splittergui.h"
#include "../VFS/vfs.h"
#include <klocale.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <kmessagebox.h>

PredefinedDevice SplitterGUI::predefinedDevices[] = {
  {i18n( "1.44 MB (3.5\")" ),   1457664},
  {i18n( "1.2 MB (5.25\")" ),   1213952},
  {i18n( "720 kB (3.5\")"  ),    730112},
  {i18n( "360 kB (5.25\")" ),    362496},
  {i18n( "100 MB (ZIP)"    ), 100431872},
  {i18n( "250 MB (ZIP)"    ), 250331136},
  {i18n( "650 MB (CD-R)" ), 650*0x100000},
  {i18n( "700 MB (CD-R)" ), 700*0x100000}
  };

SplitterGUI::SplitterGUI( TQWidget* parent,  KURL fileURL, KURL defaultDir ) :
    TQDialog( parent, "Krusader::SplitterGUI", true, 0 ), 
    userDefinedSize ( 0x100000 ), lastSelectedDevice( 0 ), resultCode( TQDialog::Rejected )
{
  predefinedDeviceNum = sizeof( predefinedDevices ) / sizeof( PredefinedDevice );

  TQGridLayout *grid = new TQGridLayout( this );
  grid->setSpacing( 6 );
  grid->setMargin( 11 );

  TQLabel *splitterLabel = new TQLabel( this, "SplitterLabel" );
  splitterLabel->setText( i18n( "Split the file %1 to directory:"  ).tqarg( vfs::pathOrURL( fileURL ) ) );
  splitterLabel->setMinimumWidth( 400 );
  grid->addWidget( splitterLabel,0 ,0 );

  urlReq = new KURLRequester( this, "DestinationDirectory" );
  urlReq->setURL( vfs::pathOrURL( defaultDir ) );
  urlReq->setMode( KFile::Directory );
  grid->addWidget( urlReq, 1 ,0 );

  TQHBox *splitSizeLine = new TQHBox( this, "splitSizeLine" );
     
  deviceCombo = new TQComboBox( splitSizeLine, "deviceCombo" );
  for( int i=0; i != predefinedDeviceNum; i++ )
    deviceCombo->insertItem( predefinedDevices[i].name );
  deviceCombo->insertItem( i18n( "User Defined" ) );

  TQLabel *spacer = new TQLabel( splitSizeLine );
  spacer->setText( " "  );
  spacer->tqsetSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum );

  TQLabel *bytesPerFile = new TQLabel( splitSizeLine, "BytesPerFile" );
  bytesPerFile->setText( i18n( "Max file size:"  ) );

  spinBox = new SplitterSpinBox( splitSizeLine, "spinbox" );
  spinBox->setMinimumWidth( 85 );
  spinBox->setEnabled( false );
    
  sizeCombo = new TQComboBox( splitSizeLine, "sizeCombo" );
  sizeCombo->insertItem( i18n( "Byte" ) );
  sizeCombo->insertItem( i18n( "kByte" ) );
  sizeCombo->insertItem( i18n( "MByte" ) );
  sizeCombo->insertItem( i18n( "GByte" ) );

  grid->addWidget( splitSizeLine,2 ,0 );

  TQFrame *separator = new TQFrame( this, "separatorLine" );
  separator->setFrameStyle( TQFrame::HLine | TQFrame::Sunken );
  separator->setFixedHeight( separator->tqsizeHint().height() );

  grid->addWidget( separator,3 ,0 );
  
  TQHBoxLayout *splitButtons = new TQHBoxLayout;
  splitButtons->setSpacing( 6 );
  splitButtons->setMargin( 0 );

  TQSpacerItem* spacer2 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  splitButtons->addItem( spacer2 );

  TQPushButton *splitBtn = new TQPushButton( this, "splitBtn" );
  splitBtn->setText( i18n("&Split") );
  splitButtons->addWidget( splitBtn );
  
  TQPushButton *cancelBtn = new TQPushButton( this, "cancelBtn" );
  cancelBtn->setText( i18n("&Cancel") );
  splitButtons->addWidget( cancelBtn );

  grid->addLayout( splitButtons,4 ,0 );
        
  setCaption(i18n("Krusader::Splitter"));

  connect( sizeCombo, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( sizeComboActivated( int ) ) );
  connect( deviceCombo, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( predefinedComboActivated( int ) ) );
  connect( cancelBtn, TQT_SIGNAL( clicked() ), this, TQT_SLOT( reject() ) );
  connect( splitBtn , TQT_SIGNAL( clicked() ), this, TQT_SLOT( splitPressed() ) );
  
  predefinedComboActivated( 0 );  
  resultCode = exec();
}

void SplitterGUI::sizeComboActivated( int item )
{
  switch ( item )
  {
  case 0:
    spinBox->setDivision( 1 );          /* byte */
    break;
  case 1:
    spinBox->setDivision( 0x400 );      /* kbyte */
    break;
  case 2:
    spinBox->setDivision( 0x100000 );   /* Mbyte */
    break;
  case 3:
    spinBox->setDivision( 0x40000000 ); /* Gbyte */
    break;
  }
}

void SplitterGUI::predefinedComboActivated( int item )
{
  int capacity = userDefinedSize;

  if( item < predefinedDeviceNum )
  {
    if( lastSelectedDevice == predefinedDeviceNum )
      userDefinedSize = spinBox->longValue();
    
    spinBox->setEnabled( false );
    capacity = predefinedDevices[item].capacity;
  }
  else
    spinBox->setEnabled( true );
  
  spinBox->setLongValue( capacity );
  
  if( capacity >= 0x40000000 )           /* Gbyte */
  {
    sizeCombo->setCurrentItem( 3 );
    spinBox->setDivision( 0x40000000 );
  }
  else if( capacity >= 0x100000 )        /* Mbyte */
  {
    sizeCombo->setCurrentItem( 2 );
    spinBox->setDivision( 0x100000 );
  }
  else if( capacity >= 0x400 )           /* kbyte */
  {
    sizeCombo->setCurrentItem( 1 );
    spinBox->setDivision( 0x400 );
  }
  else
  {
    sizeCombo->setCurrentItem( 0 );     /* byte */
    spinBox->setDivision( 1 );
  }
  
  lastSelectedDevice = item;  
}

void SplitterGUI::splitPressed()
{
  if( !vfs::fromPathOrURL( urlReq->url() ).isValid() )
  {
    KMessageBox::error( this, i18n("The directory path URL is malformed!") );
    return;
  }
  
  emit accept();
}

void SplitterGUI::keyPressEvent( TQKeyEvent *e )
{
  switch ( e->key() )
  {
  case Key_Enter :
  case Key_Return :
    emit splitPressed();
    return;
  default:
    TQDialog::keyPressEvent( e );
  }
}

#include "splittergui.moc"