~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to smb4k/dialogs/smb4kprintdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    smb4kprintdialog  -  The print dialog for Smb4K
3
 
                             -------------------
4
 
    begin                : So Apr 11 2004
5
 
    copyright            : (C) 2004-2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *   This program is free software; you can redistribute it and/or modify  *
11
 
 *   it under the terms of the GNU General Public License as published by  *
12
 
 *   the Free Software Foundation; either version 2 of the License, or     *
13
 
 *   (at your option) any later version.                                   *
14
 
 *                                                                         *
15
 
 *   This program is distributed in the hope that it will be useful, but   *
16
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
17
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
18
 
 *   General Public License for more details.                              *
19
 
 *                                                                         *
20
 
 *   You should have received a copy of the GNU General Public License     *
21
 
 *   along with this program; if not, write to the                         *
22
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
23
 
 *   MA  02111-1307 USA                                                    *
24
 
 ***************************************************************************/
25
 
 
26
 
// Qt includes
27
 
#include <QLabel>
28
 
#include <QGridLayout>
29
 
#include <QGroupBox>
30
 
#include <QDir>
31
 
 
32
 
// KDE includes
33
 
#include <klocale.h>
34
 
#include <kmessagebox.h>
35
 
#include <kdebug.h>
36
 
#include <kstandardguiitem.h>
37
 
#include <kconfiggroup.h>
38
 
#include <kurl.h>
39
 
 
40
 
// application specific includes
41
 
#include <smb4kprintdialog.h>
42
 
#include <core/smb4kprintinfo.h>
43
 
#include <core/smb4kcore.h>
44
 
#include <core/smb4khost.h>
45
 
#include <core/smb4ksettings.h>
46
 
#include <core/smb4kglobal.h>
47
 
 
48
 
using namespace Smb4KGlobal;
49
 
 
50
 
Smb4KPrintDialog::Smb4KPrintDialog( Smb4KShare *share, QWidget *parent )
51
 
: KDialog( parent ), m_share( *share )
52
 
{
53
 
  setAttribute( Qt::WA_DeleteOnClose, true );
54
 
 
55
 
  setCaption( i18n( "Print File" ) );
56
 
  setButtons( Details|User1|Cancel );
57
 
  setDefaultButton( User1 );
58
 
 
59
 
  setButtonGuiItem( User1, KStandardGuiItem::print() );
60
 
  setButtonText( Details, i18n( "Options" ) );
61
 
 
62
 
  // Get the IP address if necessary
63
 
  if ( m_share.hostIP().isEmpty() )
64
 
  {
65
 
    Smb4KHost *host = findHost( m_share.host(), m_share.workgroup() );
66
 
    m_share.setHostIP( host->ip() );
67
 
  }
68
 
 
69
 
  // Set up the view.
70
 
  setupView();
71
 
 
72
 
  enableButton( User1, false );
73
 
 
74
 
  connect( this,   SIGNAL( user1Clicked() ),
75
 
           this,   SLOT( slotUser1Clicked() ) );
76
 
 
77
 
  connect( this,   SIGNAL( cancelClicked() ),
78
 
           this,   SLOT( slotCancelClicked() ) );
79
 
 
80
 
  connect( m_file, SIGNAL( textChanged( const QString & ) ),
81
 
           this,   SLOT( slotInputValueChanged( const QString & ) ) );
82
 
 
83
 
  setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
84
 
 
85
 
  KConfigGroup group( Smb4KSettings::self()->config(), "PrintDialog" );
86
 
  restoreDialogSize( group );
87
 
}
88
 
 
89
 
 
90
 
Smb4KPrintDialog::~ Smb4KPrintDialog()
91
 
{
92
 
  // Do not delete the pointer to the Smb4KShareObject here!
93
 
}
94
 
 
95
 
 
96
 
void Smb4KPrintDialog::setupView()
97
 
{
98
 
  // Build the view:
99
 
  QWidget *main_widget = new QWidget( this );
100
 
  setMainWidget( main_widget );
101
 
 
102
 
  QGridLayout *main_widget_layout = new QGridLayout( main_widget );
103
 
  main_widget_layout->setSpacing( 5 );
104
 
  main_widget_layout->setMargin( 0 );
105
 
 
106
 
  // Printer information box
107
 
  QGroupBox *printer_box = new QGroupBox( i18n( "Printer" ), main_widget );
108
 
 
109
 
  QGridLayout *printer_box_layout = new QGridLayout( printer_box );
110
 
  printer_box_layout->setSpacing( 5 );
111
 
 
112
 
  QLabel *name_label = new QLabel( i18n( "Name:" ), printer_box );
113
 
  QLabel *name       = new QLabel( m_share.name()+
114
 
                                   (!m_share.comment().trimmed().isEmpty() ?
115
 
                                   " ("+m_share.comment()+")" :
116
 
                                   ""), printer_box );
117
 
  QLabel *host_label = new QLabel( i18n( "Host:" ), printer_box );
118
 
  QLabel *host       = new QLabel( m_share.host(), printer_box );
119
 
  QLabel *ip_label   = new QLabel( i18n( "IP Address:" ), printer_box );
120
 
  QLabel *ip         = new QLabel( m_share.hostIP().trimmed().isEmpty() ?
121
 
                                   i18n( "unknown" ) :
122
 
                                   m_share.hostIP(), printer_box );
123
 
  QLabel *wg_label   = new QLabel( i18n( "Workgroup:" ), printer_box );
124
 
  QLabel *workgroup  = new QLabel( m_share.workgroup(), printer_box );
125
 
 
126
 
  printer_box_layout->addWidget( name_label, 0, 0, 0 );
127
 
  printer_box_layout->addWidget( name, 0, 1, 0 );
128
 
  printer_box_layout->addWidget( host_label, 1, 0, 0 );
129
 
  printer_box_layout->addWidget( host, 1, 1, 0 );
130
 
  printer_box_layout->addWidget( ip_label, 2, 0, 0 );
131
 
  printer_box_layout->addWidget( ip, 2, 1, 0 );
132
 
  printer_box_layout->addWidget( wg_label, 3, 0, 0 );
133
 
  printer_box_layout->addWidget( workgroup, 3, 1, 0 );
134
 
 
135
 
  // File requester box
136
 
  QGroupBox *file_box = new QGroupBox( i18n( "File" ), main_widget );
137
 
 
138
 
  QGridLayout *file_box_layout = new QGridLayout( file_box );
139
 
  file_box_layout->setSpacing( 5 );
140
 
 
141
 
  KUrl url;
142
 
  url.setPath( QDir::homePath() );
143
 
 
144
 
  QLabel *file_label  = new QLabel( i18n( "File:" ), file_box );
145
 
  m_file              = new KUrlRequester( file_box );
146
 
  m_file->setMode( KFile::File | KFile::LocalOnly );
147
 
  m_file->setUrl( url );
148
 
 
149
 
  file_box_layout->addWidget( file_label, 0, 0, 0 );
150
 
  file_box_layout->addWidget( m_file, 0, 1, 0 );
151
 
 
152
 
  // Details widget
153
 
  QGroupBox *options_box = new QGroupBox( i18n( "Options" ), main_widget );
154
 
  setDetailsWidget( options_box );
155
 
 
156
 
  QGridLayout *options_box_layout = new QGridLayout( options_box );
157
 
  options_box_layout->setSpacing( 5 );
158
 
 
159
 
  QLabel *copies_label = new QLabel( i18n( "Copies:" ), options_box );
160
 
  m_copies             = new KIntNumInput( 1, options_box, 10 );
161
 
  m_copies->setMinimum( 1 );
162
 
 
163
 
  options_box_layout->addWidget( copies_label, 0, 0, 0 );
164
 
  options_box_layout->addWidget( m_copies, 0, 1, 0 );
165
 
 
166
 
  main_widget_layout->addWidget( printer_box, 0, 0, 0 );
167
 
  main_widget_layout->addWidget( file_box, 1, 0, 0 );
168
 
 
169
 
  printer_box->adjustSize();
170
 
  file_box->adjustSize();
171
 
}
172
 
 
173
 
 
174
 
/////////////////////////////////////////////////////////////////////////////
175
 
//  SLOT IMPLEMENTATIONS
176
 
/////////////////////////////////////////////////////////////////////////////
177
 
 
178
 
void Smb4KPrintDialog::slotUser1Clicked()
179
 
{
180
 
  if ( !m_file->url().path().trimmed().isEmpty() )
181
 
  {
182
 
    Smb4KPrintInfo printInfo( &m_share );
183
 
    printInfo.setPath( m_file->url().path().trimmed() );
184
 
    printInfo.setCopies( m_copies->value() );
185
 
 
186
 
    if ( Smb4KCore::print()->print( &printInfo ) )
187
 
    {
188
 
      connect( Smb4KCore::print(), SIGNAL( state( int ) ), this, SLOT( slotPrintStateChanged( int ) ) );
189
 
 
190
 
      enableButton( User1, false );
191
 
    }
192
 
    else
193
 
    {
194
 
      // FIXME: Should we report an error here?
195
 
    }
196
 
  }
197
 
  else
198
 
  {
199
 
    KMessageBox::error( this, i18n( "You haven't specified a file." ) );
200
 
  }
201
 
 
202
 
  KConfigGroup group( Smb4KSettings::self()->config(), "PrintDialog" );
203
 
  saveDialogSize( group, KConfigGroup::Normal );
204
 
}
205
 
 
206
 
 
207
 
void Smb4KPrintDialog::slotCancelClicked()
208
 
{
209
 
  if ( Smb4KCore::print()->isRunning() )
210
 
  {
211
 
    Smb4KCore::print()->abort();
212
 
  }
213
 
}
214
 
 
215
 
 
216
 
void Smb4KPrintDialog::slotPrintStateChanged( int state )
217
 
{
218
 
  switch ( state )
219
 
  {
220
 
    case PRINT_STOP:
221
 
    {
222
 
      accept();
223
 
 
224
 
      break;
225
 
    }
226
 
    default:
227
 
    {
228
 
      break;
229
 
    }
230
 
  }
231
 
}
232
 
 
233
 
 
234
 
void Smb4KPrintDialog::slotInputValueChanged( const QString &text )
235
 
{
236
 
  enableButton( User1, !text.isEmpty() );
237
 
}
238
 
 
239
 
 
240
 
#include "smb4kprintdialog.moc"