File: window_main_burst.cc

package info (click to toggle)
pdfchain 1%3A0.4.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,352 kB
  • sloc: cpp: 4,861; sh: 1,352; makefile: 432
file content (280 lines) | stat: -rw-r--r-- 10,384 bytes parent folder | download | duplicates (2)
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
280
/*
 * window_main_burst.cc
 * Copyright (C) Martin Singer 2009-2013 <m_power3@users.sourceforge.net>
 * pdfchain 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 3 of the License, or
 * (at your option) any later version.
 * 
 * pdfchain 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "window_main_burst.h"


/*** Combobox : Output ID *****************************************************/

cCBox_CountingBase::cCBox_CountingBase()
{
	rLStore		= cLStore_CountingBase::create();
	pTMCRecord	= rLStore->getTMCRecord();

	pack_start( mCRText );
	add_attribute( mCRText.property_text() , pTMCRecord->mTMColumn_Label );	// necessarily after 'pack_start()' !!!
	set_model( rLStore );
	set_active( 1 );
}


// Destructor
cCBox_CountingBase::~cCBox_CountingBase()
{
#ifdef PDFCHAIN_TEST
	std::cout << std::endl << "cCBox_CountingBase::~cCBox_CountingBase()";	//TEST
#endif
}


/*** Section Burst ************************************************************/

// Constructor
cSection_Burst::cSection_Burst( Gtk::Window& ref_window )
:
	Gtk::VBox( false , Pdfchain::SPACING ) ,	// homogeneous , spacing

	mHBox_SourceFile( false , Pdfchain::SPACING ) ,	// homogeneous , spacing
	mHBox_Prefix(     false , Pdfchain::SPACING ) ,
	mHBox_Digits(     false , Pdfchain::SPACING ) ,

	mVBox_Pattern(    false , Pdfchain::SPACING ) ,

	mLabel_Pattern(    _("Output PDF pattern") , Gtk::ALIGN_CENTER , Gtk::ALIGN_CENTER , false ) ,
	mLabel_Extended(   _("Extended options")   , Gtk::ALIGN_CENTER , Gtk::ALIGN_CENTER , false ) ,
	mLabel_SourceFile( _("Document:") , Gtk::ALIGN_END , Gtk::ALIGN_CENTER , false ),	// label , xalign , yalign , mnemonic
	mLabel_Prefix(     _("Prefix:")   , Gtk::ALIGN_END , Gtk::ALIGN_CENTER , false ),
	mLabel_Base(       _("Base:")     , Gtk::ALIGN_END , Gtk::ALIGN_CENTER , false ),
	mLabel_Digits(     _("Digits:")   , Gtk::ALIGN_END , Gtk::ALIGN_CENTER , false ),
	mLabel_Suffix(     _("Suffix:")   , Gtk::ALIGN_END , Gtk::ALIGN_CENTER , false ),

	mRButton_Auto(   mRBGroup_CounterDigits , _("Auto")	   , false ),	// group , label , mnemonic
	mRButton_Manual( mRBGroup_CounterDigits , _("Manual:") , false ),

	rAdjust_Digits( Gtk::Adjustment::create(
		0.0 , 0.0 , Pdfchain::Burst::ADJUST_UPPER_DIGITS , 1.0 , 1.0 , 0.0 ) ),	// value , lower , upper , step_inc , page_inc , page_size
	mSButton_Digits( rAdjust_Digits ),

	mCButton_Extension( _("Extension") , false ) ,	// label , mnemonic

	sPrefix( _("Page") ),
	sSuffix( _("") ),
	vPageNumbers( 0 ),

	mFCButton_SourceFile(   ref_window , _("Burst - Select source PDF file ...") ) ,	// parent_window , title
	mFCDialog_SelectFolder( ref_window , _("Burst - Select output folder ...") ) ,

	rSGroup_LabelPattern( Gtk::SizeGroup::create( Gtk::SIZE_GROUP_HORIZONTAL ) )
{
	// Assemble Widgets
	mLabel_Pattern.set_tooltip_text(     _("Prepare the pattern for the output PDF file names") );
	mLabel_Extended.set_tooltip_text(    _("Extended options to format the pattern") );
	mLabel_SourceFile.set_tooltip_text(  _("The source PDF file. "
		"Every single page of this document will be saved in a separate PDF file") );
	mLabel_Prefix.set_tooltip_text(	     _("Prefix part of the file name pattern") );
	mLabel_Base.set_tooltip_text(        _("Numbering base for the file counter part") );
	mLabel_Digits.set_tooltip_text(      _("Number of digits for the file counter part") );  
	mLabel_Suffix.set_tooltip_text(      _("Suffix part of the file name pattern") );  
	mCButton_Extension.set_tooltip_text( _("Appends the extension \".pdf\" part") );
	mRButton_Auto.set_tooltip_text(      _("Calculate number of counter digits automatically") );
	mRButton_Manual.set_tooltip_text(    _("Define number of counter digits manually") );

	mFrame_Pattern.set_label_widget( mLabel_Pattern );
	mExpander_Extended.set_label_widget( mLabel_Extended );

	mEntry_Prefix.set_icon_from_stock(	Gtk::Stock::CLEAR , Gtk::ENTRY_ICON_SECONDARY );
	mEntry_Suffix.set_icon_from_stock(	Gtk::Stock::CLEAR , Gtk::ENTRY_ICON_SECONDARY );

	mFCButton_SourceFile.set_halign( Gtk::ALIGN_START );
	mEntry_Prefix.set_halign(        Gtk::ALIGN_START );
	mCBox_CountingBase.set_halign(   Gtk::ALIGN_START );
	mHBox_Digits.set_halign(         Gtk::ALIGN_START );
	mEntry_Suffix.set_halign(        Gtk::ALIGN_START );

	rSGroup_LabelPattern->add_widget( mLabel_Prefix );
	rSGroup_LabelPattern->add_widget( mLabel_Suffix );
	rSGroup_LabelPattern->add_widget( mLabel_Digits );
	rSGroup_LabelPattern->add_widget( mLabel_Base );

	mHBox_SourceFile.pack_start( mLabel_SourceFile    , false , false , 0 );	// widget , expand , fill , padding
	mHBox_SourceFile.pack_start( mFCButton_SourceFile , false , true  , 0 );

	mHBox_Prefix.pack_start( mLabel_Prefix , false , false , 0 );
	mHBox_Prefix.pack_start( mEntry_Prefix , false , true  , 0 );

	mHBox_Digits.pack_start( mRButton_Auto   , false , false , 0 );
	mHBox_Digits.pack_start( mRButton_Manual , false , false , 0 );
	mHBox_Digits.pack_start( mSButton_Digits , false , false , 0 );

	mTable_Extended.set_margin_top( Pdfchain::BORDER );
	mTable_Extended.set_spacings( Pdfchain::SPACING );
	mTable_Extended.attach( mLabel_Base         , 0 , 1 , 0 , 1 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mCBox_CountingBase  , 1 , 2 , 0 , 1 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mLabel_Digits       , 0 , 1 , 1 , 2 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mHBox_Digits        , 1 , 2 , 1 , 2 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mLabel_Suffix       , 0 , 1 , 2 , 3 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mEntry_Suffix       , 1 , 2 , 2 , 3 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );
	mTable_Extended.attach( mCButton_Extension  , 1 , 2 , 3 , 4 , Gtk::FILL | Gtk::SHRINK , Gtk::FILL | Gtk::SHRINK , 0 , 0 );

	mExpander_Extended.add( mTable_Extended );

	mVBox_Pattern.set_border_width( Pdfchain::BORDER );
	mVBox_Pattern.pack_start( mHBox_Prefix );
	mVBox_Pattern.pack_start( mExpander_Extended );

	mFrame_Pattern.add( mVBox_Pattern );

	pack_start( mHBox_SourceFile , false , false , 0 );
	pack_start( mFrame_Pattern   , false , false , 0 );

	// Connect File Handler
	mEntry_Prefix.signal_icon_press().connect( sigc::mem_fun(
		*this , &cSection_Burst::onEntryIcon_Prefix_pressed ) );
		
	mEntry_Suffix.signal_icon_press().connect( sigc::mem_fun(
		*this , &cSection_Burst::onEntryIcon_Suffix_pressed ) );
		
	mCBox_CountingBase.signal_changed().connect( sigc::mem_fun(
		*this , &cSection_Burst::onCBox_CountingBase_changed ) );
		
	mRButton_Auto.signal_toggled().connect( sigc::mem_fun(
		*this , &cSection_Burst::onRButton_Auto_toggled ) );
		
	mFCButton_SourceFile.signal_file_set().connect( sigc::mem_fun(
		*this , &cSection_Burst::onFCButton_SourceFile_file_set ) );
	
	// Init Object
	init();
}


// Destructor
cSection_Burst::~cSection_Burst()
{
#ifdef PDFCHAIN_TEST
	std::cout << std::endl << "cSection_Burst::~cSection_Burst()";	//TEST
#endif
}


// Method (public) : clear
void
cSection_Burst::clear()
{
	init();
	
	vPageNumbers = 0;
	vDigits_Oct  = 0;
	vDigits_Dec  = 0;
	vDigits_Hex  = 0;
	
	return;
}


// Method (public) : create command
std::string
cSection_Burst::createCommand()
{
	std::string str_command			= "";
	std::string str_sourcefile		= "";
	std::string str_targetfolder	= "";
	std::string str_bursttemplate	= "";
	std::string str_prefix			= Glib::filename_from_utf8( mEntry_Prefix.get_text() );
	std::string str_suffix			= Glib::filename_from_utf8( mEntry_Suffix.get_text() );

	if ( "" != ( str_sourcefile = mFCButton_SourceFile.get_filename() ) ) {
		
		switch ( mFCDialog_SelectFolder.run() ) {
			case Gtk::RESPONSE_OK: {
				mFCDialog_SelectFolder.hide();

				if ( "" != ( str_targetfolder = mFCDialog_SelectFolder.get_current_folder() ) ) {

					Gtk::TreeModel::iterator iter      = mCBox_CountingBase.get_active();
					cTMCRecord_Selection*    pt_record = mCBox_CountingBase.rLStore->getTMCRecord();

					str_bursttemplate  = str_targetfolder;
					str_bursttemplate += G_DIR_SEPARATOR_S;
					str_bursttemplate += str_prefix;
					str_bursttemplate += Pdfchain::Cmd::TEMPLATE;

					if ( true == mRButton_Auto.get_active() ) {
						switch ( (*iter)[pt_record->mTMColumn_ID] ) {
							case Pdfchain::Id::COUNT_OCT :
								str_bursttemplate += Pdfchain::convert_guint_to_string( vDigits_Oct );
								break;
							case Pdfchain::Id::COUNT_DEC :
								str_bursttemplate += Pdfchain::convert_guint_to_string( vDigits_Dec );
								break;
							case Pdfchain::Id::COUNT_HEX :
								str_bursttemplate += Pdfchain::convert_guint_to_string( vDigits_Hex );
								break;
						}
					} else {
						str_bursttemplate += mSButton_Digits.get_text();
					}

					str_bursttemplate += iter->get_value( pt_record->mTMColumn_Command );
					str_bursttemplate += str_suffix;

					if ( mCButton_Extension.get_active() )
						str_bursttemplate += Pdfchain::Cmd::EXTENSION;

					str_command  = " " + Pdfchain::quote_path( str_sourcefile );
					str_command += " " + Pdfchain::Cmd::BURST;
					str_command += " " + Pdfchain::Cmd::OUTPUT;
					str_command += " " + Pdfchain::quote_path( str_bursttemplate );
				}
				break;
			}
			default:
				mFCDialog_SelectFolder.hide();
				break;
		}
	}

	return str_command;
}


// Method (protected) : init()
void 
cSection_Burst::init()
{
/*
	vPageNumbers = 0;
	vDigits_Oct  = 0;
	vDigits_Dec  = 0;
	vDigits_Hex  = 0;
*/
	mFCButton_SourceFile.clear();
	mFCDialog_SelectFolder.clear();

	mEntry_Prefix.set_text( sPrefix );
	mEntry_Suffix.set_text( sSuffix );
	mExpander_Extended.set_expanded( false );
	mRButton_Auto.set_active( true );
	rAdjust_Digits->set_value( 0.0 );
	mSButton_Digits.set_sensitive( false );
	mCBox_CountingBase.set_active( 1 );
	mCButton_Extension.set_active( true );
	
	return;
}