]> git.sesse.net Git - vlc/blob - plugins/win32/messages.cpp
* ALL: the first libvlc commit.
[vlc] / plugins / win32 / messages.cpp
1 /*****************************************************************************\r
2  * messages.cpp: log window.\r
3  *****************************************************************************\r
4  * Copyright (C) 2002 VideoLAN\r
5  *\r
6  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  * \r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
21  *****************************************************************************/\r
22 \r
23 #include <vcl.h>\r
24 #pragma hdrstop\r
25 \r
26 #include <vlc/vlc.h>\r
27 #include <vlc/intf.h>\r
28 \r
29 #include "win32_common.h"\r
30 #include "messages.h"\r
31 \r
32 //---------------------------------------------------------------------------\r
33 #pragma package(smart_init)\r
34 #pragma resource "*.dfm"\r
35 \r
36 extern intf_thread_t *p_intfGlobal;\r
37 \r
38 //---------------------------------------------------------------------------\r
39 __fastcall TMessagesDlg::TMessagesDlg( TComponent* Owner )\r
40     : TForm( Owner )\r
41 {\r
42     Icon = p_intfGlobal->p_sys->p_window->Icon;\r
43 }\r
44 //---------------------------------------------------------------------------\r
45 void __fastcall TMessagesDlg::ButtonOKClick( TObject *Sender )\r
46 {\r
47     Hide();\r
48 }\r
49 //---------------------------------------------------------------------------\r
50 void __fastcall TMessagesDlg::FormHide( TObject *Sender )\r
51 {\r
52     p_intfGlobal->p_sys->p_window->MenuMessages->Checked = false;\r
53 }\r
54 //---------------------------------------------------------------------------\r
55 void __fastcall TMessagesDlg::FormShow( TObject *Sender )\r
56 {\r
57     p_intfGlobal->p_sys->p_window->MenuMessages->Checked = true;\r
58 }\r
59 //---------------------------------------------------------------------------\r
60 void __fastcall TMessagesDlg::UpdateLog()\r
61 {\r
62     msg_subscription_t *p_sub = p_intfGlobal->p_sys->p_sub;\r
63     int                 i_start, i_stop, i_del, i_count;\r
64     int                 i_max_lines;\r
65 \r
66     vlc_mutex_lock( p_sub->p_lock );\r
67     i_stop = *p_sub->pi_stop;\r
68     vlc_mutex_unlock( p_sub->p_lock );\r
69 \r
70     if( p_sub->i_start != i_stop )\r
71     {\r
72         for( i_start = p_sub->i_start;\r
73              i_start != i_stop;\r
74              i_start = (i_start+1) % VLC_MSG_QSIZE )\r
75         {\r
76             /* Append all messages to log window */\r
77             switch( p_sub->p_msg[i_start].i_type )\r
78             {\r
79             case VLC_MSG_ERR:\r
80                 RichEditMessages->SelAttributes->Color = clRed;\r
81                 break;\r
82             case VLC_MSG_WARN:\r
83                 RichEditMessages->SelAttributes->Color = clBlack;\r
84                 break;\r
85             default:\r
86                 RichEditMessages->SelAttributes->Color = clBlue;\r
87                 break;\r
88             }\r
89 \r
90             /* Limit log size */\r
91             i_count = RichEditMessages->Lines->Count;\r
92             i_max_lines = config_GetIntVariable( "intfwin-max-lines" );\r
93             if( i_max_lines > 0 )\r
94             {\r
95                 for( i_del = 0; i_del <= i_count - i_max_lines; i_del++ )\r
96                 {\r
97                     RichEditMessages->Lines->Delete( 0 );\r
98                 }\r
99             }\r
100 \r
101             /* Add message */\r
102             if( i_max_lines )\r
103             {\r
104                 RichEditMessages->Lines->Add( p_sub->p_msg[i_start].psz_msg );\r
105             }\r
106         }\r
107 \r
108         vlc_mutex_lock( p_sub->p_lock );\r
109         p_sub->i_start = i_start;\r
110         vlc_mutex_unlock( p_sub->p_lock );\r
111     } \r
112 }\r
113 //---------------------------------------------------------------------------\r