Skip to content

Commit f986c9b

Browse files
committed
Shift some stuff around and move MythMedia to libmythdb so that we can add handling for media events in libmythui.
1 parent 8f6f7aa commit f986c9b

File tree

12 files changed

+99
-98
lines changed

12 files changed

+99
-98
lines changed

mythplugins/mythgallery/mythgallery/iconview.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ bool IconView::keyPressEvent(QKeyEvent *event)
480480
handled = false;
481481
}
482482

483-
if (action == "ESCAPE")
483+
if (action == "ESCAPE")
484484
{
485-
if (GetMythMainWindow()->IsExitingToMain())
485+
if (GetMythMainWindow()->IsExitingToMain())
486486
{
487487
while ( m_currDir != m_galleryDir &&
488488
HandleSubDirEscape(m_galleryDir) );
@@ -738,7 +738,7 @@ void IconView::customEvent(QEvent *event)
738738
MythUIButtonListItem *item = m_imageList->GetItemAt(pos);
739739
if (QFile(thumbitem->GetImageFilename()).exists())
740740
item->SetImage(thumbitem->GetImageFilename());
741-
741+
742742
if (m_imageList->GetCurrentPos() == pos)
743743
UpdateImage(item);
744744
}
@@ -993,7 +993,7 @@ void IconView::HandleDeleteCurrent(void)
993993

994994
if (!thumbitem)
995995
return;
996-
996+
997997
QString title = tr("Delete Current File or Folder");
998998
QString msg = (thumbitem->IsDir()) ?
999999
tr("Deleting 1 folder, including any subfolders and files.") :
@@ -1007,10 +1007,10 @@ void IconView::DoDeleteCurrent(bool doDelete)
10071007
if (doDelete)
10081008
{
10091009
ThumbItem *thumbitem = GetCurrentThumb();
1010-
1010+
10111011
if (!thumbitem)
10121012
return;
1013-
1013+
10141014
QFileInfo fi;
10151015
fi.setFile(thumbitem->GetPath());
10161016
GalleryUtil::Delete(fi);
@@ -1050,7 +1050,7 @@ void IconView::HandleSettings(void)
10501050

10511051
void IconView::HandleEject(void)
10521052
{
1053-
myth_eject();
1053+
MediaMonitor::ejectOpticalDisc();
10541054
}
10551055

10561056
void IconView::HandleImport(void)

mythtv/libs/libmyth/libmyth.pro

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include ( ../../settings.pro )
2-
2+
33
TEMPLATE = lib
44
TARGET = myth-$$LIBVERSION
55
CONFIG += thread dll
@@ -19,12 +19,12 @@ HEADERS += backendselect.h dbsettings.h dialogbox.h
1919
HEADERS += generictree.h langsettings.h
2020
HEADERS += managedlist.h mythconfigdialogs.h mythconfiggroups.h
2121
HEADERS += mythcontext.h mythdeque.h mythdialogs.h
22-
HEADERS += mythevent.h mythexp.h mythmedia.h mythmediamonitor.h
23-
HEADERS += mythplugin.h mythpluginapi.h
22+
HEADERS += mythevent.h mythexp.h mythmediamonitor.h
23+
HEADERS += mythplugin.h mythpluginapi.h
2424
HEADERS += mythwidgets.h mythwizard.h schemawizard.h
25-
HEADERS += output.h
26-
HEADERS += settings.h
27-
HEADERS += uilistbtntype.h uitypes.h util.h mythuifilebrowser.h
25+
HEADERS += output.h
26+
HEADERS += settings.h
27+
HEADERS += uilistbtntype.h uitypes.h mythuifilebrowser.h
2828
HEADERS += volumebase.h visual.h xmlparse.h
2929
HEADERS += mythhdd.h mythcdrom.h storagegroupeditor.h dbutil.h
3030
HEADERS += mythcommandlineparser.h mythterminal.h
@@ -50,10 +50,10 @@ SOURCES += backendselect.cpp dbsettings.cpp dialogbox.cpp
5050
SOURCES += generictree.cpp langsettings.cpp
5151
SOURCES += managedlist.cpp mythconfigdialogs.cpp mythconfiggroups.cpp
5252
SOURCES += mythcontext.cpp mythdialogs.cpp
53-
SOURCES += mythmedia.cpp mythmediamonitor.cpp
54-
SOURCES += mythplugin.cpp
53+
SOURCES += mythmediamonitor.cpp
54+
SOURCES += mythplugin.cpp
5555
SOURCES += mythwidgets.cpp mythwizard.cpp schemawizard.cpp
56-
SOURCES += output.cpp
56+
SOURCES += output.cpp
5757
SOURCES += settings.cpp
5858
SOURCES += uilistbtntype.cpp uitypes.cpp util.cpp mythuifilebrowser.cpp
5959
SOURCES += mythhdd.cpp mythcdrom.cpp storagegroupeditor.cpp dbutil.cpp
@@ -105,8 +105,8 @@ inc.files += mythwidgets.h remotefile.h oldsettings.h volumecontrol.h
105105
inc.files += settings.h uitypes.h xmlparse.h mythplugin.h mythdialogs.h
106106
inc.files += audio/audiooutput.h audio/audiosettings.h
107107
inc.files += audio/audiooutputsettings.h
108-
inc.files += util.h dbutil.h
109-
inc.files += inetcomms.h mythmedia.h mythcdrom.h mythwizard.h schemawizard.h
108+
inc.files += dbutil.h
109+
inc.files += inetcomms.h mythcdrom.h mythwizard.h schemawizard.h
110110
inc.files += uilistbtntype.h generictree.h managedlist.h mythmediamonitor.h
111111
inc.files += visual.h volumebase.h output.h langsettings.h
112112
inc.files += mythexp.h mythpluginapi.h storagegroupeditor.h

mythtv/libs/libmyth/mythcontext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace std;
2525
#include "mythevent.h"
2626
#include "dbutil.h"
2727
#include "DisplayRes.h"
28+
#include "mythmediamonitor.h"
2829

2930
#include "mythdb.h"
3031
#include "mythdirs.h"
@@ -211,7 +212,7 @@ static void plugin_cb(const QString &cmd)
211212

212213
static void eject_cb(void)
213214
{
214-
myth_eject();
215+
MediaMonitor::ejectOpticalDisc();
215216
}
216217

217218
MythContextPrivate::MythContextPrivate(MythContext *lparent)

mythtv/libs/libmyth/mythmediamonitor.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ using namespace std;
3232
#include "mediamonitor-unix.h"
3333
#endif
3434

35-
QEvent::Type MediaEvent::kEventType =
36-
(QEvent::Type) QEvent::registerEventType();
37-
3835
MediaMonitor *MediaMonitor::c_monitor = NULL;
3936

4037
// MonitorThread
@@ -889,3 +886,27 @@ const QString MediaMonitor::listDevices(void)
889886

890887
return list.join(", ");
891888
}
889+
890+
/**
891+
* \brief Eject a disk, unmount a drive, open a tray
892+
*
893+
* If the Media Monitor is enabled, we use its fully-featured routine.
894+
* Otherwise, we guess a drive and use a primitive OS-specific command
895+
*/
896+
void MediaMonitor::ejectOpticalDisc()
897+
{
898+
MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
899+
if (mon)
900+
mon->ChooseAndEjectMedia();
901+
else
902+
{
903+
VERBOSE(VB_MEDIA, "CD/DVD Monitor isn't enabled.");
904+
#ifdef __linux__
905+
VERBOSE(VB_MEDIA, "Trying Linux 'eject -T' command");
906+
myth_system("eject -T");
907+
#elif CONFIG_DARWIN
908+
VERBOSE(VB_MEDIA, "Trying 'disktool -e disk1");
909+
myth_system("disktool -e disk1");
910+
#endif
911+
}
912+
}

mythtv/libs/libmyth/mythmediamonitor.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <QPointer>
66
#include <QThread>
77
#include <QMutex>
8-
#include <QEvent>
98
#include <QList>
109

1110
#include "mythmedia.h"
@@ -19,22 +18,6 @@ struct MHData
1918
QString description;
2019
};
2120

22-
class MPUBLIC MediaEvent : public QEvent
23-
{
24-
public:
25-
MediaEvent(MediaStatus oldStatus, MythMediaDevice *pDevice) :
26-
QEvent(kEventType), m_OldStatus(oldStatus), m_Device(pDevice) {}
27-
28-
MediaStatus getOldStatus(void) const { return m_OldStatus; }
29-
MythMediaDevice* getDevice(void) { return m_Device; }
30-
31-
static Type kEventType;
32-
33-
protected:
34-
MediaStatus m_OldStatus;
35-
QPointer<MythMediaDevice> m_Device;
36-
};
37-
3821
class MediaMonitor;
3922
class MonitorThread : public QThread
4023
{
@@ -92,6 +75,8 @@ class MPUBLIC MediaMonitor : public QObject
9275
static QString defaultCDWriter();
9376
static QString defaultDVDWriter();
9477

78+
static void ejectOpticalDisc(void);
79+
9580
virtual QStringList GetCDROMBlockDevices(void) = 0;
9681

9782
public slots:
@@ -112,7 +97,7 @@ class MPUBLIC MediaMonitor : public QObject
11297
const QString listDevices(void);
11398

11499
static QString defaultDevice(const QString setting,
115-
const QString label,
100+
const QString label,
116101
const char *hardCodedDefault);
117102
MythMediaDevice *selectDrivePopup(const QString label, bool mounted=false);
118103

mythtv/libs/libmythdb/libmythdb.pro

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ HEADERS += mythtimer.h mythsignalingtimer.h mythdirs.h exitcodes.h
1818
HEADERS += lcddevice.h mythstorage.h remotefile.h decodeencode.h
1919
HEADERS += mythcorecontext.h mythsystem.h mythlocale.h storagegroup.h
2020
HEADERS += mythcoreutil.h mythdownloadmanager.h mythtranslation.h
21-
HEADERS += unzip.h unzip_p.h zipentry_p.h iso639.h iso3166.h
21+
HEADERS += unzip.h unzip_p.h zipentry_p.h iso639.h iso3166.h mythmedia.h
22+
HEADERS += util.h
2223

2324
SOURCES += mythsocket.cpp mythsocketthread.cpp msocketdevice.cpp
2425
SOURCES += mythdbcon.cpp mythdb.cpp oldsettings.cpp mythverbose.cpp
@@ -27,7 +28,7 @@ SOURCES += mythdirs.cpp mythsignalingtimer.cpp
2728
SOURCES += lcddevice.cpp mythstorage.cpp remotefile.cpp decodeencode.cpp
2829
SOURCES += mythcorecontext.cpp mythsystem.cpp mythlocale.cpp storagegroup.cpp
2930
SOURCES += mythcoreutil.cpp mythdownloadmanager.cpp mythtranslation.cpp
30-
SOURCES += unzip.cpp iso639.cpp iso3166.cpp
31+
SOURCES += unzip.cpp iso639.cpp iso3166.cpp mythmedia.cpp util.cpp
3132

3233
win32:SOURCES += msocketdevice_win.cpp
3334
unix {
@@ -50,7 +51,7 @@ inc.files += mythtimer.h lcddevice.h exitcodes.h mythdirs.h mythstorage.h
5051
inc.files += mythsocket.h mythsocket_cb.h msocketdevice.h
5152
inc.files += mythcorecontext.h mythsystem.h storagegroup.h
5253
inc.files += mythcoreutil.h mythlocale.h mythdownloadmanager.h
53-
inc.files += mythtranslation.h iso639.h iso3166.h
54+
inc.files += mythtranslation.h iso639.h iso3166.h mythmedia.h util.h
5455

5556
# Allow both #include <blah.h> and #include <libmyth/blah.h>
5657
inc2.path = $${PREFIX}/include/mythtv/libmyth

mythtv/libs/libmyth/mythmedia.cpp renamed to mythtv/libs/libmythdb/mythmedia.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ const char* MythMediaDevice::MediaErrorStrings[] =
5252
"MEDIAERR_UNSUPPORTED"
5353
};
5454

55-
MythMediaDevice::MythMediaDevice(QObject* par, const char* DevicePath,
56-
bool SuperMount, bool AllowEject)
55+
QEvent::Type MediaEvent::kEventType =
56+
(QEvent::Type) QEvent::registerEventType();
57+
58+
MythMediaDevice::MythMediaDevice(QObject* par, const char* DevicePath,
59+
bool SuperMount, bool AllowEject)
5760
: QObject(par)
5861
{
5962
m_DevicePath = DevicePath;
@@ -71,10 +74,10 @@ bool MythMediaDevice::openDevice()
7174
// Sanity check
7275
if (isDeviceOpen())
7376
return true;
74-
77+
7578
QByteArray dev = m_DevicePath.toLocal8Bit();
7679
m_DeviceHandle = open(dev.constData(), O_RDONLY | O_NONBLOCK);
77-
80+
7881
return isDeviceOpen();
7982
}
8083

@@ -86,13 +89,13 @@ bool MythMediaDevice::closeDevice()
8689

8790
int ret = close(m_DeviceHandle);
8891
m_DeviceHandle = -1;
89-
92+
9093
return (ret != -1) ? true : false;
9194
}
9295

93-
bool MythMediaDevice::isDeviceOpen() const
94-
{
95-
return (m_DeviceHandle >= 0) ? true : false;
96+
bool MythMediaDevice::isDeviceOpen() const
97+
{
98+
return (m_DeviceHandle >= 0) ? true : false;
9699
}
97100

98101
bool MythMediaDevice::performMountCmd(bool DoMount)
@@ -107,7 +110,7 @@ bool MythMediaDevice::performMountCmd(bool DoMount)
107110
if (isDeviceOpen())
108111
closeDevice();
109112

110-
if (!m_SuperMount)
113+
if (!m_SuperMount)
111114
{
112115
QString MountCommand;
113116

@@ -121,7 +124,7 @@ bool MythMediaDevice::performMountCmd(bool DoMount)
121124
MountCommand = QString("%1 %2")
122125
.arg((DoMount) ? PATHTO_MOUNT : PATHTO_UNMOUNT)
123126
.arg(m_DevicePath);
124-
127+
125128
VERBOSE(VB_MEDIA, QString("Executing '%1'").arg(MountCommand));
126129
if (myth_system(MountCommand, kMSDontBlockInputDevs) != GENERIC_EXIT_OK)
127130
{
@@ -148,12 +151,12 @@ bool MythMediaDevice::performMountCmd(bool DoMount)
148151
else
149152
VERBOSE(VB_GENERAL, QString("Failed to mount %1.")
150153
.arg(m_DevicePath));
151-
}
152-
else
154+
}
155+
else
153156
{
154157
VERBOSE(VB_MEDIA, "Disk inserted on a supermount device");
155158
// If it's a super mount then the OS will handle mounting / unmounting.
156-
// We just need to give derived classes a chance to perform their
159+
// We just need to give derived classes a chance to perform their
157160
// mount / unmount logic.
158161
if (DoMount)
159162
{
@@ -307,11 +310,11 @@ void MythMediaDevice::setSpeed(int speed)
307310
.arg(speed).arg(m_DevicePath));
308311
}
309312

310-
MediaError MythMediaDevice::lock()
311-
{
313+
MediaError MythMediaDevice::lock()
314+
{
312315
// We just open the device here, which may or may not do the trick,
313316
// derived classes can do more...
314-
if (openDevice())
317+
if (openDevice())
315318
{
316319
m_Locked = true;
317320
return MEDIAERR_OK;
@@ -321,9 +324,9 @@ MediaError MythMediaDevice::lock()
321324
}
322325

323326
MediaError MythMediaDevice::unlock()
324-
{
327+
{
325328
m_Locked = false;
326-
329+
327330
return MEDIAERR_OK;
328331
}
329332

@@ -419,9 +422,9 @@ MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt )
419422

420423
// If the status is changed we need to take some actions
421424
// depending on the old and new status.
422-
if (NewStatus != OldStatus)
425+
if (NewStatus != OldStatus)
423426
{
424-
switch (NewStatus)
427+
switch (NewStatus)
425428
{
426429
// the disk is not / should not be mounted.
427430
case MEDIASTAT_ERROR:
@@ -438,7 +441,7 @@ MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt )
438441
// get rid of the compiler warning...
439442
break;
440443
}
441-
444+
442445
// Don't fire off transitions to / from unknown states
443446
if (m_Status != MEDIASTAT_UNKNOWN && OldStatus != MEDIASTAT_UNKNOWN)
444447
emit statusChanged(OldStatus, this);

mythtv/libs/libmyth/mythmedia.h renamed to mythtv/libs/libmythdb/mythmedia.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <QObject>
55
#include <QMap>
66
#include <QString>
7+
#include <QEvent>
8+
#include <QPointer>
79

810
#include "mythexp.h"
911

@@ -168,4 +170,20 @@ class MPUBLIC MythMediaDevice : public QObject
168170
ext_to_media_t m_ext_to_media; ///< Map of extension to media type.
169171
};
170172

173+
class MPUBLIC MediaEvent : public QEvent
174+
{
175+
public:
176+
MediaEvent(MediaStatus oldStatus, MythMediaDevice *pDevice) :
177+
QEvent(kEventType), m_OldStatus(oldStatus), m_Device(pDevice) {}
178+
179+
MediaStatus getOldStatus(void) const { return m_OldStatus; }
180+
MythMediaDevice* getDevice(void) { return m_Device; }
181+
182+
static Type kEventType;
183+
184+
protected:
185+
MediaStatus m_OldStatus;
186+
QPointer<MythMediaDevice> m_Device;
187+
};
188+
171189
#endif

mythtv/libs/libmythdb/mythversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// Update this whenever the plug-in API changes.
1212
/// Including changes in the libmythdb, libmyth, libmythtv, libmythav* and
1313
/// libmythui class methods used by plug-ins.
14-
#define MYTH_BINARY_VERSION "0.25.20110125-3"
14+
#define MYTH_BINARY_VERSION "0.25.20110126-1"
1515

1616
/** \brief Increment this whenever the MythTV network protocol changes.
1717
*

0 commit comments

Comments
 (0)