summaryrefslogtreecommitdiffstats
path: root/src/k3bmediaselectiondialog.cpp
blob: 360729791ecc0533267bc2dce93c5046958317ae (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
/* 
 *
 * $Id: sourceheader 380067 2005-01-19 13:03:46Z trueg $
 * Copyright (C) 2005 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 "k3bmediaselectiondialog.h"
#include "k3bmediaselectioncombobox.h"
#include "k3bmediacache.h"
#include "k3bapplication.h"

#include <klocale.h>

#include <qlayout.h>
#include <qlabel.h>


K3bMediaSelectionDialog::K3bMediaSelectionDialog( QWidget* parent, 
						  const QString& title, 
						  const QString& text, 
						  bool modal )
  : KDialogBase( KDialogBase::Plain, 
		 title.isEmpty() ? i18n("Medium Selection") : title, 
		 Ok|Cancel, 
		 Ok,
		 parent,
		 0,
		 modal )
{
  QGridLayout* lay = new QGridLayout( plainPage() );

  QLabel* label = new QLabel( text.isEmpty() ? i18n("Please select a medium:") : text, plainPage() );
  m_combo = new K3bMediaSelectionComboBox( plainPage() );

  //  lay->setMargin( marginHint() );
  lay->setSpacing( spacingHint() );
  lay->addWidget( label, 0, 0 );
  lay->addWidget( m_combo, 1, 0 );
  lay->setRowStretch( 2, 1 );

  connect( m_combo, SIGNAL(selectionChanged(K3bDevice::Device*)),
	   this, SLOT(slotSelectionChanged(K3bDevice::Device*)) );

  slotSelectionChanged( m_combo->selectedDevice() );
}


K3bMediaSelectionDialog::~K3bMediaSelectionDialog()
{
}


void K3bMediaSelectionDialog::setWantedMediumType( int type )
{
  m_combo->setWantedMediumType( type );
}


void K3bMediaSelectionDialog::setWantedMediumState( int state )
{
  m_combo->setWantedMediumState( state );
}


void K3bMediaSelectionDialog::setWantedMediumContent( int content )
{
  m_combo->setWantedMediumContent( content );
}


K3bDevice::Device* K3bMediaSelectionDialog::selectedDevice() const
{
  return m_combo->selectedDevice();
}


void K3bMediaSelectionDialog::slotSelectionChanged( K3bDevice::Device* dev )
{
  enableButtonOK( dev != 0 );
}


K3bDevice::Device* K3bMediaSelectionDialog::selectMedium( int type, int state, int content,
							  QWidget* parent, 
							  const QString& title, const QString& text,
							  bool* canceled )
{
  K3bMediaSelectionDialog dlg( parent, title, text );
  dlg.setWantedMediumType( type );
  dlg.setWantedMediumState( state );
  dlg.setWantedMediumContent( content );

  // even if no usable medium is inserted the combobox shows the "insert one" message
  // so it's not sufficient to check for just one entry to check if there only is a 
  // single useable medium
  if( ( dlg.selectedDevice() && dlg.m_combo->count() == 1 ) 
      || dlg.exec() == Accepted ) {
    if( canceled )
      *canceled = false;
    return dlg.selectedDevice();
  }
  else {
    if( canceled )
      *canceled = true;
    return 0;
  }
}


K3bDevice::Device* K3bMediaSelectionDialog::selectMedium( int type, int state, 
							  QWidget* parent, 
							  const QString& title, const QString& text,
							  bool* canceled )
{
  return selectMedium( type, state, K3bMedium::CONTENT_ALL, parent, title, text, canceled );
}

#include "k3bmediaselectiondialog.moc"