1 /*****************************************************************************
2 * messages.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
43 #define NMAXFILE 512 // at least 256
47 #define TEXTMAXBUF 512 // at least 500
50 /*****************************************************************************
52 *****************************************************************************/
54 Messages::Messages( intf_thread_t *p_intf, CBaseWindow *p_parent,
56 : CBaseWindow( p_intf, p_parent, h_inst )
61 hWnd = CreateWindow( _T("VLC WinCE"), _T("Messages"),
62 WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX,
63 0, 0, /*CW_USEDEFAULT*/300, /*CW_USEDEFAULT*/300,
64 p_parent->GetHandle(), NULL, h_inst, (void *)this );
67 /***********************************************************************
72 Processes messages sent to the main window.
73 ***********************************************************************/
74 LRESULT Messages::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
78 TCHAR psz_text[TEXTMAXBUF];
86 shidi.dwMask = SHIDIM_FLAGS;
87 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
88 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
90 SHInitDialog( &shidi );
92 hListView = CreateWindow( WC_LISTVIEW, NULL,
93 WS_VISIBLE | WS_CHILD | LVS_REPORT |
94 LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL |
95 WS_BORDER | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
96 hwnd, NULL, hInst, NULL );
97 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
101 lv.fmt = LVCFMT_LEFT ;
102 ListView_InsertColumn( hListView, 0, &lv );
104 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
107 case WM_WINDOWPOSCHANGED:
110 if( !GetClientRect( hwnd, &rect ) ) break;
111 SetWindowPos( hListView, 0, 0, 0,
112 rect.right - rect.left, rect.bottom - rect.top, 0 );
115 lv.cx = rect.right - rect.left;
116 lv.mask = LVCF_WIDTH;
117 ListView_SetColumn( hListView, 0, &lv );
122 SHSipPreference( hwnd, SIP_DOWN );
123 SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
142 ListView_DeleteAllItems( hListView );
146 memset( &(ofn), 0, sizeof(ofn) );
147 ofn.lStructSize = sizeof(ofn);
148 ofn.hwndOwner = hwnd;
149 ofn.lpstrFile = _T("");
150 ofn.nMaxFile = NMAXFILE;
151 ofn.lpstrFilter = _T("Text (*.txt)\0*.txt\0");
152 ofn.lpstrTitle = _T("Save File As");
153 ofn.Flags = OFN_HIDEREADONLY;
154 ofn.lpstrDefExt = _T("txt");
156 if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
158 fichier = CreateFile( ofn.lpstrFile, GENERIC_WRITE,
159 FILE_SHARE_READ|FILE_SHARE_WRITE,
161 FILE_ATTRIBUTE_NORMAL, NULL );
163 if( fichier != INVALID_HANDLE_VALUE )
167 //SetFilePointer( fichier, 0, NULL, FILE_END );
168 for( n = 0; n < ListView_GetItemCount( hListView ); n++ )
170 ListView_GetItemText( hListView, n, 0, psz_text,
172 string text_out = (string)_TOMB(psz_text) + "\n";
173 WriteFile( fichier, text_out.c_str(), text_out.size(),
174 (LPDWORD)&i_dummy, NULL );
176 FlushFileBuffers( fichier );
177 CloseHandle(fichier);
190 return DefWindowProc( hwnd, msg, wp, lp );
193 void Messages::UpdateLog()
195 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
199 vlc_mutex_lock( p_sub->p_lock );
200 i_stop = *p_sub->pi_stop;
201 vlc_mutex_unlock( p_sub->p_lock );
203 if( p_sub->i_start != i_stop )
205 for( i_start = p_sub->i_start; i_start != i_stop;
206 i_start = (i_start+1) % VLC_MSG_QSIZE )
208 switch( p_sub->p_msg[i_start].i_type )
212 if( p_intf->p_libvlc->i_verbose < 0 ) continue;
215 if( p_intf->p_libvlc->i_verbose < 1 ) continue;
218 if( p_intf->p_libvlc->i_verbose < 2 ) continue;
222 /* Append all messages to log window */
223 debug = p_sub->p_msg[i_start].psz_module;
225 switch( p_sub->p_msg[i_start].i_type )
227 case VLC_MSG_INFO: debug += ": "; break;
228 case VLC_MSG_ERR: debug += " error: "; break;
229 case VLC_MSG_WARN: debug += " warning: "; break;
230 default: debug += " debug: "; break;
234 debug += p_sub->p_msg[i_start].psz_msg;
238 lv.pszText = TEXT("");
241 lv.iItem = ListView_GetItemCount( hListView );
242 ListView_InsertItem( hListView, &lv );
243 ListView_SetItemText( hListView, lv.iItem, 0,
244 (TCHAR *)_FROMMB(debug.c_str()) );
247 vlc_mutex_lock( p_sub->p_lock );
248 p_sub->i_start = i_start;
249 vlc_mutex_unlock( p_sub->p_lock );