File: DateTime.cpp

package info (click to toggle)
bsc 2.27-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,640 kB
  • ctags: 2,610
  • sloc: cpp: 14,100; perl: 114; makefile: 46
file content (174 lines) | stat: -rw-r--r-- 6,826 bytes parent folder | download
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
/********************************************************************
 * Copyright (C) 2005, 2006 Piotr Pszczolkowski
 *-------------------------------------------------------------------
 * This file is part of BSCommander (Beesoft Commander).
 *
 * BsC 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.
 *
 * BsC 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 BsC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *******************************************************************/

/*------- include files:
-------------------------------------------------------------------*/
#include "DateTime.h"
#include "ViewTableItem.h"
#include "Shared.h"
#include "InfoField.h"
#include "Config.h"
#include <qlayout.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qdatetimeedit.h>

/*------- local constants:
-------------------------------------------------------------------*/
const QString DateTime::DATE_TIME_FORMAT    = "yyyy/MM/dd  hh:mm:ss";
const QString DateTime::TOUCH_CMD           = "touch -c -t";
const QString DateTime::TOUCH_FORMAT        = " yyyyMMddhhmm.ss ";
//...................................................................
const QString DateTime::CAPTION             = QT_TR_NOOP( "Date/time of last file modyfication." );
const QString DateTime::BTN_ACCEPT_LABEL    = QT_TR_NOOP( "&Accept" );
const QString DateTime::CB_MUSTER_LABEL     = QT_TR_NOOP( "&Use '%1' like muster" );
const QString DateTime::GBOX_EDIT_CAPTION   = QT_TR_NOOP( "Date and Time" );
const QString DateTime::GBOX_MUSTER_CAPTION = QT_TR_NOOP( "Date/time muster" );

//*******************************************************************
// DateTime                                              CONSTRUCTOR
//*******************************************************************
DateTime::DateTime( QWidget* const in_parent, const ViewTable::SelectedItems& in_items, const ViewTableItem* const in_muster )
: QDialog( in_parent )
, d_items( in_items )
, d_muster( in_muster )
, d_accept_btn( new QPushButton( tr(BTN_ACCEPT_LABEL), this ))
, d_cancel_btn( new QPushButton( tr(Shared::CloseBtnLabel), this ))
, d_muster_cb( new QCheckBox( tr(CB_MUSTER_LABEL).arg(in_muster->name()), this ))
, d_edit_dt( 0 )
, d_muster_if( 0 )
{
	setCaption( tr(CAPTION) );
	Shared::add_icon( d_accept_btn, tr(Shared::AcceptIcon) );
	Shared::add_icon( d_cancel_btn, tr(Shared::CloseIcon) );
	
	QHBoxLayout* const main_layout = new QHBoxLayout( this );
	main_layout->setMargin( Shared::LayoutMargin );
	main_layout->setSpacing( Shared::LayoutSpacing );
	
	QVBoxLayout* const data_layout = new QVBoxLayout;
	data_layout->addWidget( make_edit_area() );
	data_layout->addWidget( d_muster_cb );
	data_layout->addWidget( make_muster_area() );
	main_layout->addLayout( data_layout );
	
	QVBoxLayout* const btn_layout = new QVBoxLayout;
	btn_layout->addStretch( Shared::OverStretch );
	btn_layout->addWidget( d_cancel_btn );
	btn_layout->addWidget( d_accept_btn );
	main_layout->addLayout( btn_layout );
	
	if( !d_muster ) d_muster_cb->setEnabled( FALSE );

	connect( d_accept_btn, SIGNAL( clicked     ()                   ),
				this        , SLOT  ( accept      ()                   ));
	connect( d_cancel_btn, SIGNAL( clicked     ()                   ),
				this        , SLOT  ( cancel      ()                   ));
	connect( d_muster_cb , SIGNAL( toggled     ( bool )             ),
				this        , SLOT  ( use_muster  ( bool )             ));
	connect( d_edit_dt   , SIGNAL( valueChanged( const QDateTime& ) ),
				this        , SLOT  ( no_muster   ( const QDateTime& ) ));
}
// end of DateTime

//*******************************************************************
// make_edit_area                                            PRIVATE
//*******************************************************************
QWidget* DateTime::make_edit_area()
{
	QGroupBox* const gbox = new QGroupBox( 1, Qt::Horizontal, tr(GBOX_EDIT_CAPTION), this );
	d_edit_dt = new QDateTimeEdit( d_items[0]->last_modified(), gbox );
	d_edit_dt->dateEdit()->setOrder( QDateEdit::YMD );
	return gbox;
}
// end of make_edit_area

//*******************************************************************
// make_muster_area                                         PRIVATE
//*******************************************************************
QWidget* DateTime::make_muster_area()
{
	QGroupBox* const gbox = new QGroupBox( 1, Qt::Horizontal, tr(GBOX_MUSTER_CAPTION), this );
	QString muster = Shared::EmptyStr;

	if( d_muster ) {
		const QDateTime dt( d_muster->last_modified() );
		muster = dt.toString( tr(DATE_TIME_FORMAT) );
	}
	d_muster_if = new InfoField( muster, gbox );

	return gbox;
}
// end of make_muster_area

//*******************************************************************
// accept                                               PRIVATE slot
//*******************************************************************
void DateTime::accept()
{
	ViewTable::SelectedItems::const_iterator it = d_items.begin();
	while( it != d_items.end() ) {
		QString cmd = TOUCH_CMD;
		cmd += d_edit_dt->dateTime().toString( TOUCH_FORMAT );
		cmd += (*it)->path();
		const int retval = system( cmd );
		if( -1 == retval ) {
		}
		++it;
	}
	
	QDialog::accept();
}
// end of accept

//*******************************************************************
// cancel                                               PRIVATE slot
//*******************************************************************
void DateTime::cancel()
{
	reject();
}
// end of close

//*******************************************************************
// use_muster                                           PRIVATE slot
//*******************************************************************
void DateTime::use_muster( bool in_checked )
{
	if( in_checked ) {
		d_edit_dt->setDateTime( d_muster->last_modified() );
		d_muster_cb->setChecked( TRUE );
	}
}
// end of use_muster

//*******************************************************************
// no_muster                                            PRIVATE slot
//*******************************************************************
void DateTime::no_muster( const QDateTime& in_dt )
{
	if( in_dt != d_muster->last_modified() ) {
		if( d_muster_cb->isChecked() ) {
			d_muster_cb->setChecked( FALSE );
		}
	}
}
// end of no_muster