1
/***************************************************************************
2
smb4kprintdialog - The print dialog for Smb4K
5
copyright : (C) 2004-2008 by Alexander Reinholdt
6
email : dustpuppy@users.berlios.de
7
***************************************************************************/
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. *
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. *
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, *
24
***************************************************************************/
28
#include <QGridLayout>
34
#include <kmessagebox.h>
36
#include <kstandardguiitem.h>
37
#include <kconfiggroup.h>
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>
48
using namespace Smb4KGlobal;
50
Smb4KPrintDialog::Smb4KPrintDialog( Smb4KShare *share, QWidget *parent )
51
: KDialog( parent ), m_share( *share )
53
setAttribute( Qt::WA_DeleteOnClose, true );
55
setCaption( i18n( "Print File" ) );
56
setButtons( Details|User1|Cancel );
57
setDefaultButton( User1 );
59
setButtonGuiItem( User1, KStandardGuiItem::print() );
60
setButtonText( Details, i18n( "Options" ) );
62
// Get the IP address if necessary
63
if ( m_share.hostIP().isEmpty() )
65
Smb4KHost *host = findHost( m_share.host(), m_share.workgroup() );
66
m_share.setHostIP( host->ip() );
72
enableButton( User1, false );
74
connect( this, SIGNAL( user1Clicked() ),
75
this, SLOT( slotUser1Clicked() ) );
77
connect( this, SIGNAL( cancelClicked() ),
78
this, SLOT( slotCancelClicked() ) );
80
connect( m_file, SIGNAL( textChanged( const QString & ) ),
81
this, SLOT( slotInputValueChanged( const QString & ) ) );
83
setMinimumWidth( sizeHint().width() > 350 ? sizeHint().width() : 350 );
85
KConfigGroup group( Smb4KSettings::self()->config(), "PrintDialog" );
86
restoreDialogSize( group );
90
Smb4KPrintDialog::~ Smb4KPrintDialog()
92
// Do not delete the pointer to the Smb4KShareObject here!
96
void Smb4KPrintDialog::setupView()
99
QWidget *main_widget = new QWidget( this );
100
setMainWidget( main_widget );
102
QGridLayout *main_widget_layout = new QGridLayout( main_widget );
103
main_widget_layout->setSpacing( 5 );
104
main_widget_layout->setMargin( 0 );
106
// Printer information box
107
QGroupBox *printer_box = new QGroupBox( i18n( "Printer" ), main_widget );
109
QGridLayout *printer_box_layout = new QGridLayout( printer_box );
110
printer_box_layout->setSpacing( 5 );
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()+")" :
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() ?
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 );
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 );
135
// File requester box
136
QGroupBox *file_box = new QGroupBox( i18n( "File" ), main_widget );
138
QGridLayout *file_box_layout = new QGridLayout( file_box );
139
file_box_layout->setSpacing( 5 );
142
url.setPath( QDir::homePath() );
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 );
149
file_box_layout->addWidget( file_label, 0, 0, 0 );
150
file_box_layout->addWidget( m_file, 0, 1, 0 );
153
QGroupBox *options_box = new QGroupBox( i18n( "Options" ), main_widget );
154
setDetailsWidget( options_box );
156
QGridLayout *options_box_layout = new QGridLayout( options_box );
157
options_box_layout->setSpacing( 5 );
159
QLabel *copies_label = new QLabel( i18n( "Copies:" ), options_box );
160
m_copies = new KIntNumInput( 1, options_box, 10 );
161
m_copies->setMinimum( 1 );
163
options_box_layout->addWidget( copies_label, 0, 0, 0 );
164
options_box_layout->addWidget( m_copies, 0, 1, 0 );
166
main_widget_layout->addWidget( printer_box, 0, 0, 0 );
167
main_widget_layout->addWidget( file_box, 1, 0, 0 );
169
printer_box->adjustSize();
170
file_box->adjustSize();
174
/////////////////////////////////////////////////////////////////////////////
175
// SLOT IMPLEMENTATIONS
176
/////////////////////////////////////////////////////////////////////////////
178
void Smb4KPrintDialog::slotUser1Clicked()
180
if ( !m_file->url().path().trimmed().isEmpty() )
182
Smb4KPrintInfo printInfo( &m_share );
183
printInfo.setPath( m_file->url().path().trimmed() );
184
printInfo.setCopies( m_copies->value() );
186
if ( Smb4KCore::print()->print( &printInfo ) )
188
connect( Smb4KCore::print(), SIGNAL( state( int ) ), this, SLOT( slotPrintStateChanged( int ) ) );
190
enableButton( User1, false );
194
// FIXME: Should we report an error here?
199
KMessageBox::error( this, i18n( "You haven't specified a file." ) );
202
KConfigGroup group( Smb4KSettings::self()->config(), "PrintDialog" );
203
saveDialogSize( group, KConfigGroup::Normal );
207
void Smb4KPrintDialog::slotCancelClicked()
209
if ( Smb4KCore::print()->isRunning() )
211
Smb4KCore::print()->abort();
216
void Smb4KPrintDialog::slotPrintStateChanged( int state )
234
void Smb4KPrintDialog::slotInputValueChanged( const QString &text )
236
enableButton( User1, !text.isEmpty() );
240
#include "smb4kprintdialog.moc"