summaryrefslogtreecommitdiffstats
path: root/src/k3bmediacontentsview.cpp
blob: d23c85a64e539242ba913c18baacec1518b46dd3 (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
/* 
 *
 * $Id: k3bmediacontentsview.cpp 627519 2007-01-26 22:37:51Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <[email protected]>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
 *
 * 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 "k3bmediacontentsview.h"

#include <k3bmediacache.h>
#include <k3bapplication.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpixmap.h>
#include <tqwidgetstack.h>


class K3bMediaContentsView::Private
{
public:
  K3bMedium medium;
  int supportedMediumContent;
  int supportedMediumTypes;
  int supportedMediumStates;

  bool autoReload;
};


K3bMediaContentsView::K3bMediaContentsView( bool withHeader,
					    int mediumContent,
					    int mediumTypes,
					    int mediumState,
					    TQWidget* tqparent,
					    const char* name )
  : K3bContentsView( withHeader, tqparent, name )
{
  d = new Private;
  d->supportedMediumContent = mediumContent;
  d->supportedMediumTypes = mediumTypes;
  d->supportedMediumStates = mediumState;
  d->autoReload = true;

  connect( k3bappcore->mediaCache(), TQT_SIGNAL(mediumChanged(K3bDevice::Device*)),
	   this, TQT_SLOT(slotMediumChanged(K3bDevice::Device*)) );
}


K3bMediaContentsView::~K3bMediaContentsView()
{
  delete d;
}


void K3bMediaContentsView::setAutoReload( bool b )
{
  d->autoReload = b;
}


int K3bMediaContentsView::supportedMediumContent() const
{
  return d->supportedMediumContent;
}


int K3bMediaContentsView::supportedMediumTypes() const
{
  return d->supportedMediumTypes;
}


int K3bMediaContentsView::supportedMediumStates() const
{
  return d->supportedMediumStates;
}


const K3bMedium& K3bMediaContentsView::medium() const
{
  return d->medium;
}


K3bDevice::Device* K3bMediaContentsView::device() const
{
  return medium().device();
}


void K3bMediaContentsView::setMedium( const K3bMedium& m )
{
  d->medium = m;
}


void K3bMediaContentsView::reload( K3bDevice::Device* dev )
{
  reload( k3bappcore->mediaCache()->medium( dev ) );
}


void K3bMediaContentsView::reload( const K3bMedium& m )
{
  setMedium( m );
  reload();
}


void K3bMediaContentsView::reload()
{
  enableInteraction( true );
  reloadMedium();
}


void K3bMediaContentsView::enableInteraction( bool enable )
{
  mainWidget()->setEnabled( enable );
}


void K3bMediaContentsView::slotMediumChanged( K3bDevice::Device* dev )
{
  // FIXME: derive a K3bContentsStack from TQWidgetStack and let it set an active flag
  // to replace this hack
  if( TQWidgetStack* stack = dynamic_cast<TQWidgetStack*>( parentWidget() ) )
    if( stack->visibleWidget() != this )
      return;

  if( !d->autoReload /*|| !isActive()*/ )
    return;

  if( dev == device() ) {
    K3bMedium m = k3bappcore->mediaCache()->medium( dev );

    // no need to reload if the medium did not change (this is even
    // important since K3b blocks the devices in action and after
    // the release they are signalled as changed)
    if( m == medium() ) {
      kdDebug() << k_funcinfo << " medium did not change" << endl;
      enableInteraction( true );
    }
    else if( m.content() & supportedMediumContent() &&
	     m.diskInfo().mediaType() & supportedMediumTypes() &&
	     m.diskInfo().diskState() & supportedMediumStates() ) {
      kdDebug() << k_funcinfo << " new supported medium found" << endl;
      reload( m );
    }
    else {
      kdDebug() << k_funcinfo << " unsupported medium found" << endl;
      enableInteraction( false );
    }
  }
}

#include "k3bmediacontentsview.moc"