summaryrefslogtreecommitdiffstats
path: root/src/projects/k3baudiocdtextwidget.cpp
blob: a180f02161a563970d7fcc58b2de0f1f059d52de (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 *
 * $Id: k3baudiocdtextwidget.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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.
 * See the file "COPYING" for the exact licensing terms.
 */

#include "k3baudiocdtextwidget.h"
#include "base_k3baudiocdtextallfieldswidget.h"

#include "k3baudiodoc.h"
#include "k3baudiotrack.h"
#include <k3bcdtextvalidator.h>

#include <tqcheckbox.h>
#include <tqtoolbutton.h>
#include <tqpushbutton.h>
#include <tqptrlist.h>
#include <tqlayout.h>
#include <tqgroupbox.h>

#include <klineedit.h>
#include <tdelocale.h>
#include <kdialogbase.h>
#include <kiconloader.h>


class K3bAudioCdTextWidget::AllFieldsDialog : public KDialogBase
{
public:
  AllFieldsDialog( TQWidget* parent )
    : KDialogBase( parent,
		   "cdtext_allfields_dialog",
		   true,
		   i18n("CD-Text"),
		   Ok|Cancel,
		   Ok,
		   true ) {
    w = new base_K3bAudioCdTextAllFieldsWidget( this );
    setMainWidget( w );
  }

  base_K3bAudioCdTextAllFieldsWidget* w;
};


K3bAudioCdTextWidget::K3bAudioCdTextWidget( TQWidget* parent, const char* name )
  : base_K3bAudioCdTextWidget( parent, name ),
    m_doc(0)
{
  m_allFieldsDlg = new AllFieldsDialog( this );

  m_buttonCopyTitle->setPixmap( SmallIcon( "edit-copy" ) );
  m_buttonCopyPerformer->setPixmap( SmallIcon( "edit-copy" ) );

  m_allFieldsDlg->w->m_buttonCopyTitle->setPixmap( SmallIcon( "edit-copy" ) );
  m_allFieldsDlg->w->m_buttonCopyPerformer->setPixmap( SmallIcon( "edit-copy" ) );
  m_allFieldsDlg->w->m_buttonCopySongwriter->setPixmap( SmallIcon( "edit-copy" ) );
  m_allFieldsDlg->w->m_buttonCopyComposer->setPixmap( SmallIcon( "edit-copy" ) );
  m_allFieldsDlg->w->m_buttonCopyArranger->setPixmap( SmallIcon( "edit-copy" ) );

  TQValidator* cdTextVal = new K3bCdTextValidator( TQT_TQOBJECT(this) );
  m_editTitle->setValidator( cdTextVal );
  m_editPerformer->setValidator( cdTextVal );

  m_allFieldsDlg->w->m_editTitle->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editPerformer->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editDisc_id->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editUpc_ean->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editMessage->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editArranger->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editSongwriter->setValidator( cdTextVal );
  m_allFieldsDlg->w->m_editComposer->setValidator( cdTextVal );

  connect( m_allFieldsDlg->w->m_buttonCopyTitle, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotCopyTitle()) );
  connect( m_allFieldsDlg->w->m_buttonCopyPerformer, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotCopyPerformer()) );
  connect( m_allFieldsDlg->w->m_buttonCopyArranger, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotCopyArranger()) );
  connect( m_allFieldsDlg->w->m_buttonCopySongwriter, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotCopySongwriter()) );
  connect( m_allFieldsDlg->w->m_buttonCopyComposer, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotCopyComposer()) );

  connect( m_buttonMoreFields, TQT_SIGNAL(clicked()),
	   this, TQT_SLOT(slotMoreFields()) );
}


K3bAudioCdTextWidget::~K3bAudioCdTextWidget()
{
}

void K3bAudioCdTextWidget::load( K3bAudioDoc* doc )
{
  m_doc = doc;
  m_groupCdText->setChecked( doc->cdText() );

  m_editTitle->setText( doc->title() );
  m_editPerformer->setText( doc->artist() );

  m_allFieldsDlg->w->m_editTitle->setText( doc->title() );
  m_allFieldsDlg->w->m_editPerformer->setText( doc->artist() );
  m_allFieldsDlg->w->m_editDisc_id->setText( doc->disc_id() );
  m_allFieldsDlg->w->m_editUpc_ean->setText( doc->upc_ean() );
  m_allFieldsDlg->w->m_editArranger->setText( doc->arranger() );
  m_allFieldsDlg->w->m_editSongwriter->setText( doc->songwriter() );
  m_allFieldsDlg->w->m_editComposer->setText( doc->composer() );
  m_allFieldsDlg->w->m_editMessage->setText( doc->cdTextMessage() );
}

void K3bAudioCdTextWidget::save( K3bAudioDoc* doc )
{
  m_doc = doc;
  doc->writeCdText( m_groupCdText->isChecked() );

  // we save the title and artist values from the main view since
  // the dialog is only updated before it is shown
  doc->setTitle( m_editTitle->text() );
  doc->setArtist( m_editPerformer->text() );
  doc->setDisc_id( m_allFieldsDlg->w->m_editDisc_id->text() );
  doc->setUpc_ean( m_allFieldsDlg->w->m_editUpc_ean->text() );
  doc->setArranger( m_allFieldsDlg->w->m_editArranger->text() );
  doc->setSongwriter( m_allFieldsDlg->w->m_editSongwriter->text() );
  doc->setComposer( m_allFieldsDlg->w->m_editComposer->text() );
  doc->setCdTextMessage( m_allFieldsDlg->w->m_editMessage->text() );
}


void K3bAudioCdTextWidget::slotMoreFields()
{
  // update dlg to current state
  m_allFieldsDlg->w->m_editTitle->setText( m_editTitle->text() );
  m_allFieldsDlg->w->m_editPerformer->setText( m_editPerformer->text() );

  // save old settings
  TQString title = m_allFieldsDlg->w->m_editTitle->text();
  TQString performer = m_allFieldsDlg->w->m_editPerformer->text();
  TQString disc_id = m_allFieldsDlg->w->m_editDisc_id->text();
  TQString upc_ean = m_allFieldsDlg->w->m_editUpc_ean->text();
  TQString arranger = m_allFieldsDlg->w->m_editArranger->text();
  TQString songwriter = m_allFieldsDlg->w->m_editSongwriter->text();
  TQString composer = m_allFieldsDlg->w->m_editComposer->text();
  TQString message = m_allFieldsDlg->w->m_editMessage->text();

  // exec dlg
  if( m_allFieldsDlg->exec() == TQDialog::Accepted ) {
    // accept new entries
    m_editTitle->setText( m_allFieldsDlg->w->m_editTitle->text() );
    m_editPerformer->setText( m_allFieldsDlg->w->m_editPerformer->text() );
  }
  else {
    // reset
    m_allFieldsDlg->w->m_editTitle->setText( title );
    m_allFieldsDlg->w->m_editPerformer->setText( performer );
    m_allFieldsDlg->w->m_editDisc_id->setText( disc_id );
    m_allFieldsDlg->w->m_editUpc_ean->setText( upc_ean );
    m_allFieldsDlg->w->m_editArranger->setText( arranger );
    m_allFieldsDlg->w->m_editSongwriter->setText( songwriter );
    m_allFieldsDlg->w->m_editComposer->setText( composer );
    m_allFieldsDlg->w->m_editMessage->setText( message );
  }
}


void K3bAudioCdTextWidget::setChecked( bool b )
{
  m_groupCdText->setChecked( b );
}

bool K3bAudioCdTextWidget::isChecked() const
{
  return m_groupCdText->isChecked();
}


void K3bAudioCdTextWidget::slotCopyTitle()
{
  K3bAudioTrack* track = m_doc->firstTrack();
  while( track ) {
    track->setTitle( m_allFieldsDlg->isVisible() 
		     ? m_allFieldsDlg->w->m_editTitle->text()
		     : m_editTitle->text() );
    track = track->next();
  }
}

void K3bAudioCdTextWidget::slotCopyPerformer()
{
  K3bAudioTrack* track = m_doc->firstTrack();
  while( track ) {
    track->setPerformer( m_allFieldsDlg->isVisible() 
			 ? m_allFieldsDlg->w->m_editPerformer->text() 
			 : m_editPerformer->text() );
    track = track->next();
  }
}

void K3bAudioCdTextWidget::slotCopyArranger()
{
  K3bAudioTrack* track = m_doc->firstTrack();
  while( track ) {
    track->setArranger( m_allFieldsDlg->w->m_editArranger->text() );
    track = track->next();
  }
}

void K3bAudioCdTextWidget::slotCopySongwriter()
{
  K3bAudioTrack* track = m_doc->firstTrack();
  while( track ) {
    track->setSongwriter( m_allFieldsDlg->w->m_editSongwriter->text() );
    track = track->next();
  }
}

void K3bAudioCdTextWidget::slotCopyComposer()
{
  K3bAudioTrack* track = m_doc->firstTrack();
  while( track ) {
    track->setComposer( m_allFieldsDlg->w->m_editComposer->text() );
    track = track->next();
  }
}


#include "k3baudiocdtextwidget.moc"