]> git.sesse.net Git - vlc/blob - modules/gui/kde/kde.cpp
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[vlc] / modules / gui / kde / kde.cpp
1 /*****************************************************************************
2  * kde.cpp : KDE plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: kde.cpp,v 1.1 2002/08/04 17:23:43 sam Exp $
6  *
7  * Authors: Andres Krapf <dae@chez.com> Sun Mar 25 2001
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include "common.h"
25
26 #include "interface.h"
27
28 #include <iostream>
29
30 #include <kaction.h>
31 #include <kapp.h>
32 #include <kaboutdata.h>
33 #include <kcmdlineargs.h>
34 #include <klocale.h>
35 #include <kmainwindow.h>
36 #include <kstdaction.h>
37 #include <qwidget.h>
38
39 /*****************************************************************************
40  * The local class.
41  *****************************************************************************/
42 class KInterface;
43 class KAboutData;
44
45 class KThread
46 {
47     private:
48         KThread ( KThread &thread ) { };
49         KThread &operator= ( KThread &thread ) { return ( *this ); };
50
51         intf_thread_t *p_intf;
52         
53     public:
54         KThread(intf_thread_t *p_intf);
55         ~KThread();
56
57         // These methods get exported to the core
58         static int     open    ( vlc_object_t * );
59         static void    close   ( vlc_object_t * );
60         static void    run     ( intf_thread_t * );
61 };
62
63 /*****************************************************************************
64  * Module descriptor
65  *****************************************************************************/
66 vlc_module_begin();
67 #ifdef WIN32
68     int i = 90;
69 #else
70     int i = getenv( "DISPLAY" ) == NULL ? 8 : 85;
71 #endif
72     set_description( _("KDE interface module") );
73     set_capability( "interface", i );
74     set_program( "kvlc" );
75     //set_callbacks( E_(Open), E_(Close) );
76     set_callbacks( KThread::open, KThread::close );
77 vlc_module_end();
78
79 /*****************************************************************************
80  * KThread::KThread: KDE interface constructor
81  *****************************************************************************/
82 KThread::KThread(intf_thread_t *p_intf)
83 {
84     this->p_intf = p_intf;
85
86     p_intf->p_sys->p_about =
87       new KAboutData( "VideoLAN Client", I18N_NOOP("Kvlc"), VERSION,
88          _("This is the VideoLAN client, a DVD and MPEG player. It can play "
89            "MPEG and MPEG 2 files from a file or from a network source."),
90          KAboutData::License_GPL,
91          _("(C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 - the VideoLAN Team"),
92          0, 0, "");
93
94     char *authors[][2] = {
95         { "the VideoLAN Team", "<videolan@videolan.org>" },
96         { NULL, NULL },
97     };
98
99     for ( int i = 0; NULL != authors[i][0]; i++ ) {
100         p_intf->p_sys->p_about->addAuthor( authors[i][0], 0, authors[i][1] );
101     }
102
103     int argc = 1;
104     char *argv[] = { p_intf->p_vlc->psz_object_name, NULL };
105     KCmdLineArgs::init( argc, argv, p_intf->p_sys->p_about );
106
107     p_intf->p_sys->p_app = new KApplication();
108     p_intf->p_sys->p_window = new KInterface(p_intf);
109     p_intf->p_sys->p_window->setCaption( VOUT_TITLE " (KDE interface)" );
110
111     p_intf->p_sys->p_input = NULL;
112 }
113
114 /*****************************************************************************
115  * KThread::~KThread: KDE interface destructor
116  *****************************************************************************/
117 KThread::~KThread()
118 {
119     if( p_intf->p_sys->p_input )
120     {
121         vlc_object_release( p_intf->p_sys->p_input );
122     }
123
124     /* XXX: can be deleted if the user closed the window ! */
125     //delete p_intf->p_sys->p_window;
126
127     delete p_intf->p_sys->p_app;
128     delete p_intf->p_sys->p_about;
129 }
130
131 /*****************************************************************************
132  * KThread::open: initialize and create window
133  *****************************************************************************/
134 int KThread::open(vlc_object_t *p_this)
135 {
136     intf_thread_t *p_intf = (intf_thread_t *)p_this;
137
138     /* Allocate instance and initialize some members */
139     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
140     if( p_intf->p_sys == NULL )
141     {
142         msg_Err( p_intf, "out of memory" );
143         return( 1 );
144     }
145
146     p_intf->pf_run = KThread::run;
147
148     p_intf->p_sys->p_thread = new KThread(p_intf);
149     return ( 0 );
150 }
151
152 /*****************************************************************************
153  * KThread::close: destroy interface window
154  *****************************************************************************/
155 void KThread::close(vlc_object_t *p_this)
156 {
157     intf_thread_t *p_intf = (intf_thread_t *)p_this;
158
159     delete p_intf->p_sys->p_thread;
160     free( p_intf->p_sys );
161 }
162
163 /*****************************************************************************
164  * KThread::run: KDE thread
165  *****************************************************************************
166  * This part of the interface is in a separate thread so that we can call
167  * exec() from within it without annoying the rest of the program.
168  *****************************************************************************/
169 void KThread::run(intf_thread_t *p_intf)
170 {
171     p_intf->p_sys->p_window->show();
172     p_intf->p_sys->p_app->exec();
173 }
174