]> git.sesse.net Git - vlc/blob - plugins/kde/kde.cpp
* ALL: the first libvlc commit.
[vlc] / plugins / kde / kde.cpp
1 /*****************************************************************************
2  * kde.cpp : KDE plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: kde.cpp,v 1.13 2002/06/01 12:31:59 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 "kde_common.h"
25
26 #include "kde_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  * Capabilities defined in the other files.
41  *****************************************************************************/
42 static void intf_getfunctions( function_list_t * p_function_list );
43
44 /*****************************************************************************
45  * Build configuration tree.
46  *****************************************************************************/
47 extern "C"
48 {
49
50 MODULE_CONFIG_START
51 MODULE_CONFIG_STOP
52
53 MODULE_INIT_START
54     SET_DESCRIPTION( _("KDE interface module") )
55 #ifndef WIN32
56     if( getenv( "DISPLAY" ) == NULL )
57     {
58         ADD_CAPABILITY( INTF, 8 )
59     }
60     else
61 #endif
62     {
63         ADD_CAPABILITY( INTF, 85 )
64     }
65     ADD_PROGRAM( "kvlc" )
66 MODULE_INIT_STOP
67
68 MODULE_ACTIVATE_START
69     intf_getfunctions( &p_module->p_functions->intf );
70 MODULE_ACTIVATE_STOP
71
72 MODULE_DEACTIVATE_START
73 MODULE_DEACTIVATE_STOP
74
75 } // extern "C"
76
77 /*****************************************************************************
78  * The local class.
79  *****************************************************************************/
80 class KInterface;
81 class KAboutData;
82
83 class KThread
84 {
85     private:
86         KThread ( KThread &thread ) { };
87         KThread &operator= ( KThread &thread ) { return ( *this ); };
88
89         intf_thread_t *p_intf;
90         
91     public:
92         KThread(intf_thread_t *p_intf);
93         ~KThread();
94
95         // These methods get exported to the core
96         static int     open    ( intf_thread_t *p_intf );
97         static void    close   ( intf_thread_t *p_intf );
98         static void    run     ( intf_thread_t *p_intf );
99 };
100
101 /*****************************************************************************
102  * Functions exported as capabilities.
103  *****************************************************************************/
104 static void intf_getfunctions( function_list_t * p_function_list )
105 {
106     p_function_list->functions.intf.pf_open  = KThread::open;
107     p_function_list->functions.intf.pf_close = KThread::close;
108     p_function_list->functions.intf.pf_run   = KThread::run;
109 }
110
111 /*****************************************************************************
112  * KThread::KThread: KDE interface constructor
113  *****************************************************************************/
114 KThread::KThread(intf_thread_t *p_intf)
115 {
116     this->p_intf = p_intf;
117
118     p_intf->p_sys->p_about =
119         new KAboutData( "VideoLAN Client", I18N_NOOP("Kvlc"), VERSION,
120             "This is the VideoLAN client, a DVD and MPEG player. It can play MPEG and MPEG 2 files from a file or from a network source.", KAboutData::License_GPL,
121             "(C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 - the VideoLAN Team", 0, 0, "dae@chez.com");
122
123     char *authors[][2] = {
124         { "the VideoLAN Team", "<videolan@videolan.org>" },
125         { NULL, NULL },
126     };
127
128     for ( int i = 0; NULL != authors[i][0]; i++ ) {
129         p_intf->p_sys->p_about->addAuthor( authors[i][0], 0, authors[i][1] );
130     }
131
132     int argc = 1;
133     char *argv[] = { p_intf->p_vlc->psz_object_name, NULL };
134     KCmdLineArgs::init( argc, argv, p_intf->p_sys->p_about );
135
136     p_intf->p_sys->p_app = new KApplication();
137     p_intf->p_sys->p_window = new KInterface(p_intf);
138     p_intf->p_sys->p_window->setCaption( VOUT_TITLE " (KDE interface)" );
139 }
140
141 /*****************************************************************************
142  * KThread::~KThread: KDE interface destructor
143  *****************************************************************************/
144 KThread::~KThread()
145 {
146     /* XXX: can be deleted if the user closed the window ! */
147     //delete p_intf->p_sys->p_window;
148
149     delete p_intf->p_sys->p_app;
150     delete p_intf->p_sys->p_about;
151 }
152
153 /*****************************************************************************
154  * KThread::open: initialize and create window
155  *****************************************************************************/
156 int KThread::open(intf_thread_t *p_intf)
157 {
158     /* Allocate instance and initialize some members */
159     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
160     if( p_intf->p_sys == NULL )
161     {
162         msg_Err( p_intf, "out of memory" );
163         return( 1 );
164     }
165
166     p_intf->p_sys->p_thread = new KThread(p_intf);
167     return ( 0 );
168 }
169
170 /*****************************************************************************
171  * KThread::close: destroy interface window
172  *****************************************************************************/
173 void KThread::close(intf_thread_t *p_intf)
174 {
175     delete p_intf->p_sys->p_thread;
176     free( p_intf->p_sys );
177 }
178
179 /*****************************************************************************
180  * KThread::run: KDE thread
181  *****************************************************************************
182  * This part of the interface is in a separate thread so that we can call
183  * exec() from within it without annoying the rest of the program.
184  *****************************************************************************/
185 void KThread::run(intf_thread_t *p_intf)
186 {
187     p_intf->p_sys->p_window->show();
188     p_intf->p_sys->p_app->exec();
189 }
190