added: more polish to the content stuff.
[xbmc:xbmc-antiquated.git] / xbmc / GUIDialogContextMenu.cpp
1 #include "stdafx.h"
2 #include "GUIDialogContextMenu.h"
3 #include "GUIButtonControl.h"
4 #include "GUIDialogNumeric.h"
5 #include "GUIDialogGamepad.h"
6 #include "GUIDialogFileBrowser.h"
7 #include "GUIDialogContentSettings.h"
8 #include "GUIWindowVideoFiles.h"
9 #include "application.h"
10 #include "GUIPassword.h"
11 #include "util.h"
12 #include "GUIDialogMediaSource.h"
13 #include "GUIDialogLockSettings.h"
14 #include "MediaManager.h"
15 #include "GUIWindowMusicBase.h"
16
17 #define BACKGROUND_IMAGE 999
18 #define BACKGROUND_BOTTOM 998
19 #define BUTTON_TEMPLATE 1000
20 #define SPACE_BETWEEN_BUTTONS 2
21
22 CGUIDialogContextMenu::CGUIDialogContextMenu(void):CGUIDialog(WINDOW_DIALOG_CONTEXT_MENU, "DialogContextMenu.xml")
23 {
24   m_iClickedButton = -1;
25   m_iNumButtons = 0;
26 }
27 CGUIDialogContextMenu::~CGUIDialogContextMenu(void)
28 {}
29 bool CGUIDialogContextMenu::OnMessage(CGUIMessage &message)
30 {
31   if (message.GetMessage() == GUI_MSG_CLICKED)
32   { // someone has been clicked - deinit...
33     m_iClickedButton = message.GetSenderId() - BUTTON_TEMPLATE;
34     Close();
35     return true;
36   }
37   return CGUIDialog::OnMessage(message);
38 }
39
40 void CGUIDialogContextMenu::OnInitWindow()
41 { // disable the template button control
42   CGUIControl *pControl = (CGUIControl *)GetControl(BUTTON_TEMPLATE);
43   if (pControl)
44   {
45     pControl->SetVisible(false);
46   }
47   m_iClickedButton = -1;
48   // set initial control focus
49   m_lastControlID = BUTTON_TEMPLATE + 1;
50   CGUIDialog::OnInitWindow();
51 }
52
53 void CGUIDialogContextMenu::ClearButtons()
54 { // destroy our buttons (if we have them from a previous viewing)
55   for (int i = 1; i <= m_iNumButtons; i++)
56   {
57     // get the button to remove...
58     CGUIControl *pControl = (CGUIControl *)GetControl(BUTTON_TEMPLATE + i);
59     if (pControl)
60     {
61       // remove the control from our list
62       Remove(BUTTON_TEMPLATE + i);
63       // kill the button
64       pControl->FreeResources();
65       delete pControl;
66     }
67   }
68   m_iNumButtons = 0;
69 }
70
71 int CGUIDialogContextMenu::AddButton(int iLabel)
72 {
73   return AddButton(g_localizeStrings.Get(iLabel));
74 }
75
76 int CGUIDialogContextMenu::AddButton(const CStdString &strLabel)
77 { // add a button to our control
78   CGUIButtonControl *pButtonTemplate = (CGUIButtonControl *)GetControl(BUTTON_TEMPLATE);
79   if (!pButtonTemplate) return 0;
80   CGUIButtonControl *pButton = new CGUIButtonControl(*pButtonTemplate);
81   if (!pButton) return 0;
82   // set the button's ID and position
83   m_iNumButtons++;
84   DWORD dwID = BUTTON_TEMPLATE + m_iNumButtons;
85   pButton->SetID(dwID);
86   pButton->SetPosition(pButtonTemplate->GetXPosition(), (m_iNumButtons - 1)*(pButtonTemplate->GetHeight() + SPACE_BETWEEN_BUTTONS));
87   pButton->SetVisible(true);
88   pButton->SetNavigation(dwID - 1, dwID + 1, dwID, dwID);
89   pButton->SetLabel(strLabel);
90   Add(pButton);
91   // and update the size of our menu
92   CGUIControl *pControl = (CGUIControl *)GetControl(BACKGROUND_IMAGE);
93   if (pControl)
94   {
95     pControl->SetHeight(m_iNumButtons*(pButtonTemplate->GetHeight() + SPACE_BETWEEN_BUTTONS));
96     CGUIControl *pControl2 = (CGUIControl *)GetControl(BACKGROUND_BOTTOM);
97     if (pControl2)
98       pControl2->SetPosition(pControl2->GetXPosition(), pControl->GetYPosition() + pControl->GetHeight());
99   }
100   return m_iNumButtons;
101 }
102 void CGUIDialogContextMenu::DoModal(int iWindowID /*= WINDOW_INVALID */)
103 {
104   // update the navigation of the first and last buttons
105   CGUIControl *pControl = (CGUIControl *)GetControl(BUTTON_TEMPLATE + 1);
106   if (pControl)
107     pControl->SetNavigation(BUTTON_TEMPLATE + m_iNumButtons, pControl->GetControlIdDown(), pControl->GetControlIdLeft(), pControl->GetControlIdRight());
108   pControl = (CGUIControl *)GetControl(BUTTON_TEMPLATE + m_iNumButtons);
109   if (pControl)
110     pControl->SetNavigation(pControl->GetControlIdUp(), BUTTON_TEMPLATE + 1, pControl->GetControlIdLeft(), pControl->GetControlIdRight());
111   // update our default control
112   if (m_dwDefaultFocusControlID <= BUTTON_TEMPLATE || m_dwDefaultFocusControlID > (DWORD)(BUTTON_TEMPLATE + m_iNumButtons))
113     m_dwDefaultFocusControlID = BUTTON_TEMPLATE + 1;
114   // check the default control has focus...
115   while (m_dwDefaultFocusControlID <= (DWORD)(BUTTON_TEMPLATE + m_iNumButtons) && !(GetControl(m_dwDefaultFocusControlID)->CanFocus()))
116     m_dwDefaultFocusControlID++;
117   CGUIDialog::DoModal();
118 }
119
120 int CGUIDialogContextMenu::GetButton()
121 {
122   return m_iClickedButton;
123 }
124
125 float CGUIDialogContextMenu::GetHeight()
126 {
127   CGUIControl *pControl = (CGUIControl *)GetControl(BACKGROUND_IMAGE);
128   if (pControl)
129     return pControl->GetHeight();
130   else
131     return CGUIDialog::GetHeight();
132 }
133
134 float CGUIDialogContextMenu::GetWidth()
135 {
136   CGUIControl *pControl = (CGUIControl *)GetControl(BACKGROUND_IMAGE);
137   if (pControl)
138     return pControl->GetWidth();
139   else
140     return CGUIDialog::GetWidth();
141 }
142 int CGUIDialogContextMenu::GetNumButtons()
143 {
144   return m_iNumButtons;
145 }
146 void CGUIDialogContextMenu::EnableButton(int iButton, bool bEnable)
147 {
148   CGUIControl *pControl = (CGUIControl *)GetControl(BUTTON_TEMPLATE + iButton);
149   if (pControl) pControl->SetEnabled(bEnable);
150 }
151
152 bool CGUIDialogContextMenu::BookmarksMenu(const CStdString &strType, const CFileItem *item, float posX, float posY)
153 {
154   // TODO: This should be callable even if we don't have any valid items
155   if (!item)
156     return false;
157
158   bool bMaxRetryExceeded = false;
159   if (g_guiSettings.GetInt("masterlock.maxretries") != 0)
160   bMaxRetryExceeded = !(item->m_iBadPwdCount < g_guiSettings.GetInt("masterlock.maxretries"));
161
162   // Get the share object from our file object
163   VECSHARES *shares = g_settings.GetSharesFromType(strType);
164   if (!shares) return false;
165   CShare *share = NULL;
166   for (unsigned int i = 0; i < shares->size(); i++)
167   {
168     CShare &testShare = shares->at(i);
169     if (CUtil::IsDVD(testShare.strPath))
170     {
171       if (!item->IsDVD())
172         continue;
173     }
174     else
175     {
176       if (!testShare.strPath.Equals(item->m_strPath))
177         continue;
178     }
179     // paths match, what about share name - only match the leftmost
180     // characters as the label may contain other info (status for instance)
181     if (item->GetLabel().Left(testShare.strName.size()).Equals(testShare.strName))
182     {
183       share = &testShare;
184       break;
185     }
186   }
187
188   // popup the context menu
189   CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU);
190   if (pMenu)
191   {
192     // check where we are
193     bool bMyProgramsMenu = ("myprograms" == strType);
194     // For DVD Drive Context menu stuff, we can also check where we are, so playin dvd can be dependet to the section!
195     bool bIsDVDContextMenu  = false;
196     bool bIsDVDMediaPresent = false;
197     
198     // load our menu
199     pMenu->Initialize();
200
201     // GeminiServer: DVD Drive Context menu stuff
202     int btn_PlayDisc = 0;
203     int btn_Eject = 0;
204     int btn_Rip;
205     if (item->IsDVD() || item->IsCDDA())
206     {
207       // We need to check if there is a detected is inserted!
208       if ( CDetectDVDMedia::IsDiscInDrive() )
209       {
210         btn_PlayDisc = pMenu->AddButton(341); // Play CD/DVD!
211
212         CCdInfo *pCdInfo = CDetectDVDMedia::GetCdInfo(); 
213         if ( pCdInfo->IsAudio(1) || pCdInfo->IsCDExtra(1) || pCdInfo->IsMixedMode(1) )
214           btn_Rip = pMenu->AddButton(600);
215
216         bIsDVDMediaPresent = true;
217       }
218       btn_Eject = pMenu->AddButton(13391);  // Eject/Load CD/DVD!
219       bIsDVDContextMenu = true;
220     }
221
222     CStdString strDefault = GetDefaultShareNameByType(strType);
223     
224     // add the needed buttons
225     int btn_AddShare=0;
226     int btn_EditPath=0;
227     int btn_Default=0;
228     int btn_Delete=0;
229     int btn_setThumb=0;
230     int btn_RemoveThumb=0;
231     int btn_ClearDefault=0;
232     int btn_SetContent=0;
233     if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources() || g_passwordManager.bMasterUser)
234     {
235       if (share)
236       {
237         btn_EditPath = pMenu->AddButton(1027); // Edit Source
238         btn_Default = pMenu->AddButton(13335); // Set as Default
239         btn_Delete = pMenu->AddButton(522); // Remove Source
240
241         btn_setThumb = pMenu->AddButton(20019);
242         if (share->m_strThumbnailImage != "")
243           btn_RemoveThumb = pMenu->AddButton(20057);
244       }
245       if (!strDefault.IsEmpty())
246         btn_ClearDefault = pMenu->AddButton(13403); // Clear Default
247
248       if (strType == "video" && !CUtil::IsDVD(share->strPath))
249         btn_SetContent = pMenu->AddButton(20333);
250
251       btn_AddShare = pMenu->AddButton(1026); // Add Source
252     }
253
254     // This if statement should always be the *last* one to add buttons
255     // Only show share lock stuff if masterlock isn't disabled
256     int btn_LockShare = 0; // Lock Share
257     int btn_ResetLock = 0; // Reset Share Lock
258     int btn_RemoveLock = 0; // Remove Share Lock
259     int btn_ReactivateLock = 0; // Reactivate Share Lock
260     int btn_ChangeLock = 0; // Change Share Lock;
261
262     if (share && LOCK_MODE_EVERYONE != g_settings.m_vecProfiles[0].getLockMode())
263     {
264       if (share->m_iHasLock == 0 && (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources() || g_passwordManager.bMasterUser))
265         btn_LockShare = pMenu->AddButton(12332);
266       else if (share->m_iHasLock == 1)
267       {
268         btn_RemoveLock = pMenu->AddButton(12335);
269       }
270       else if (share->m_iHasLock == 2)
271       {
272         btn_RemoveLock = pMenu->AddButton(12335);
273         if (!bMaxRetryExceeded)
274           btn_ChangeLock = pMenu->AddButton(12356);
275         if (bMaxRetryExceeded)
276           btn_ResetLock = pMenu->AddButton(12334);
277       }
278     }
279     if (share && !g_passwordManager.bMasterUser && share->m_iHasLock == 1)
280       btn_ReactivateLock = pMenu->AddButton(12353);
281
282     int btn_Settings = pMenu->AddButton(5);         // Settings
283
284     // set the correct position
285     pMenu->SetPosition(posX - pMenu->GetWidth() / 2, posY - pMenu->GetHeight() / 2);
286     pMenu->DoModal();
287     
288     int btn = pMenu->GetButton();
289     if (btn > 0)
290     {
291       if (btn == btn_EditPath)
292       {
293         if (g_settings.m_iLastLoadedProfileIndex == 0)
294         {
295           if (!g_passwordManager.IsMasterLockUnlocked(true))
296             return false;
297         }
298         else
299           if (!g_passwordManager.IsProfileLockUnlocked())
300             return false;
301         
302         return CGUIDialogMediaSource::ShowAndEditMediaSource(strType, *share);
303       }
304       else if (btn == btn_Delete)
305       {
306         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
307         {
308           if (!g_passwordManager.IsProfileLockUnlocked())
309             return false;
310         }
311         else if (!g_passwordManager.IsMasterLockUnlocked(true))
312           return false;
313 // prompt user if they want to really delete the bookmark
314         if (CGUIDialogYesNo::ShowAndGetInput(bMyProgramsMenu ? 758 : 751, 0, 750, 0))
315         {
316           // check default before we delete, as deletion will kill the share object
317           if (!strDefault.IsEmpty())
318           {
319             if (share->strName.Equals(strDefault))
320               ClearDefault(strType);
321           }
322           
323           // delete this share
324           g_settings.DeleteBookmark(strType, share->strName, share->strPath);
325           return true;
326         }
327       }
328       else if (btn == btn_AddShare)
329       {
330         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
331         {
332           if (!g_passwordManager.IsProfileLockUnlocked())
333             return false;
334         }
335         else if (!g_passwordManager.IsMasterLockUnlocked(true))
336           return false;
337         
338         return CGUIDialogMediaSource::ShowAndAddMediaSource(strType);
339       }
340       else if (btn == btn_Default)
341       {
342         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
343         {
344           if (!g_passwordManager.IsProfileLockUnlocked())
345             return false;
346         }
347         else if (!g_passwordManager.IsMasterLockUnlocked(true))
348           return false;
349         
350         // make share default
351         SetDefault(strType, share->strName);
352         return true;
353       }
354       else if (btn == btn_ClearDefault)
355       {
356         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
357         {
358           if (!g_passwordManager.IsProfileLockUnlocked())
359             return false;
360         }
361         else if (!g_passwordManager.IsMasterLockUnlocked(true))
362           return false;
363         // remove share default
364         ClearDefault(strType);
365         return true;
366       }
367       else if (btn == btn_setThumb)
368       {
369         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
370         {
371           if (!g_passwordManager.IsProfileLockUnlocked())
372             return false;
373         }
374         else if (!g_passwordManager.IsMasterLockUnlocked(true))
375           return false;
376
377         CStdString strThumb;
378         VECSHARES shares;
379         g_mediaManager.GetLocalDrives(shares);
380
381         if (CGUIDialogFileBrowser::ShowAndGetImage(shares,g_localizeStrings.Get(20056),strThumb))
382         {
383           g_settings.UpdateBookmark(strType,share->strName,"thumbnail",strThumb);
384           
385           CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_BOOKMARKS);
386           m_gWindowManager.SendThreadMessage(msg);        
387           return true;
388         }
389
390         return false;
391       }
392       else if (btn == btn_RemoveThumb)
393       {
394         if (g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources())
395         {
396           if (!g_passwordManager.IsProfileLockUnlocked())
397             return false;
398         }
399         else if (!g_passwordManager.IsMasterLockUnlocked(true))
400           return false;
401
402         g_settings.UpdateBookmark(strType,share->strName,"thumbnail","");
403         CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_BOOKMARKS);
404         m_gWindowManager.SendThreadMessage(msg);        
405         return true;
406       }
407       else if (btn == btn_SetContent)
408       {
409         bool bRunScan=false, bScanRecursively=true, bUseDirNames=false;
410         SScraperInfo info;
411         if (CGUIDialogContentSettings::ShowForDirectory(share->strPath,info,bRunScan,bScanRecursively,bUseDirNames))
412         {
413           if (bRunScan)
414           {
415             CGUIWindowVideoFiles* pWindow = (CGUIWindowVideoFiles*)m_gWindowManager.GetWindow(WINDOW_VIDEO_FILES);
416             pWindow->OnScan(share->strPath,info,bUseDirNames?1:0,bScanRecursively?1:0);
417           }
418         }
419       }
420       else if (btn == btn_PlayDisc)
421       {
422         // Ok Play now the Media CD/DVD!
423         return CAutorun::PlayDisc();
424       }
425       else if (btn == btn_Eject)
426       {
427         CIoSupport TrayIO;
428         if (TrayIO.GetTrayState() == TRAY_OPEN)
429         {
430           TrayIO.CloseTray();
431           return true;
432         }
433         else
434         {
435           TrayIO.EjectTray();
436           return true;
437         }
438       }
439       else if (btn == btn_Rip)
440       {
441         CGUIWindowMusicBase::OnRipCD();
442         return true;
443       }
444       else if (btn == btn_LockShare)
445       {
446         bool bResult = false;
447         CStdString strNewPassword = "";
448         int iButton=0;
449         // prompt user for mastercode when changing lock settings) only for default user
450         if (!g_passwordManager.IsMasterLockUnlocked(true))    
451           return false;
452
453         CGUIDialogLockSettings* pDialog = (CGUIDialogLockSettings*)m_gWindowManager.GetWindow(WINDOW_DIALOG_LOCK_SETTINGS);
454         if (pDialog)
455           bResult = CGUIDialogLockSettings::ShowAndGetLock(share->m_iLockMode,strNewPassword);
456         else // OLD DEPRECATED
457         {
458
459           // popup the context menu
460           CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU);
461           if (pMenu)
462           {
463             // load our menu
464             pMenu->Initialize();
465             // add the needed buttons
466             pMenu->AddButton(12337); // 1: Numeric Password
467             pMenu->AddButton(12338); // 2: XBOX gamepad button combo
468             pMenu->AddButton(12339); // 3: Full-text Password
469
470             // set the correct position
471             pMenu->SetPosition(posX - pMenu->GetWidth() / 2, posY - pMenu->GetHeight() / 2);
472             pMenu->DoModal();
473
474             iButton = pMenu->GetButton();
475             switch (pMenu->GetButton())
476             {
477             case 1:  // 1: Numeric Password
478               if (!CGUIDialogNumeric::ShowAndVerifyNewPassword(strNewPassword))
479                 return false;
480               break;
481             case 2:  // 2: Gamepad Password
482               if (!CGUIDialogGamepad::ShowAndVerifyNewPassword(strNewPassword))
483                 return false;
484               break;
485             case 3:  // 3: Fulltext Password
486               if (!CGUIDialogKeyboard::ShowAndVerifyNewPassword(strNewPassword))
487                 return false;
488               break;
489             default:  // Not supported, abort
490               return false;
491               break;
492             }
493           }
494           share->m_iLockMode = iButton;
495           bResult = true;
496         }
497         if (!bResult)
498           return false;
499         // password entry and re-entry succeeded, write out the lock data
500         share->m_iHasLock = 2;
501         g_settings.BeginBookmarkTransaction();
502         g_settings.UpdateBookmark(strType, share->strName, "lockcode", strNewPassword);
503         strNewPassword.Format("%i",share->m_iLockMode);
504         g_settings.UpdateBookmark(strType, share->strName, "lockmode", strNewPassword);
505         g_settings.UpdateBookmark(strType, share->strName, "badpwdcount", "0");
506         g_settings.CommitBookmarkTransaction();
507
508         CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_BOOKMARKS);
509         m_gWindowManager.SendThreadMessage(msg);        
510         return true;
511
512       }
513       else if (btn == btn_ResetLock)
514       {
515         // prompt user for profile lock when changing lock settings
516         if (!g_passwordManager.IsMasterLockUnlocked(true))
517           return false;
518
519         g_settings.UpdateBookmark(strType, share->strName, "badpwdcount", "0");
520         CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_BOOKMARKS);
521         m_gWindowManager.SendThreadMessage(msg);        
522         return true;
523       }
524       else if (btn == btn_RemoveLock)
525       {
526         if (!g_passwordManager.IsMasterLockUnlocked(true))
527           return false;
528
529         if (!CGUIDialogYesNo::ShowAndGetInput(12335, 0, 750, 0))
530           return false;
531         
532         share->m_iHasLock = 0;
533         g_settings.BeginBookmarkTransaction();
534         g_settings.UpdateBookmark(strType, share->strName, "lockmode", "0");
535         g_settings.UpdateBookmark(strType, share->strName, "lockcode", "0");
536         g_settings.UpdateBookmark(strType, share->strName, "badpwdcount", "0");
537         g_settings.CommitBookmarkTransaction();
538         CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_BOOKMARKS);
539         m_gWindowManager.SendThreadMessage(msg);        
540
541         return true;
542       }
543       else if (btn == btn_ReactivateLock)
544       {
545         if (!bMaxRetryExceeded)
546         {
547           // don't prompt user for mastercode when reactivating a lock
548           g_passwordManager.LockBookmark(strType, share->strName,true);
549           return true;
550         }
551         else  // this should never happen, but if it does, don't perform any action
552           return false;
553       }
554       else if (btn == btn_ChangeLock)
555       {
556         if (!g_passwordManager.IsMasterLockUnlocked(true))    
557           return false;
558
559         CStdString strNewPW;
560               CStdString strNewLockMode;
561         bool bResult=false;                 
562         CGUIDialogLockSettings* pDialog = (CGUIDialogLockSettings*)m_gWindowManager.GetWindow(WINDOW_DIALOG_LOCK_SETTINGS);
563         if (pDialog)
564         {
565           bResult = CGUIDialogLockSettings::ShowAndGetLock(share->m_iLockMode,strNewPW);
566           if (bResult)
567             strNewLockMode.Format("%i",share->m_iLockMode);
568         }
569         else // OLD DEPRECATED
570         {
571           switch (item->m_iLockMode)
572           {
573           case 1:  // 1: Numeric Password
574             if (!CGUIDialogNumeric::ShowAndVerifyNewPassword(strNewPW))
575               return false;
576             else strNewLockMode = "1";
577             break;
578           case 2:  // 2: Gamepad Password
579             if (!CGUIDialogGamepad::ShowAndVerifyNewPassword(strNewPW))
580               return false;
581             else strNewLockMode = "2";
582             break;
583           case 3:  // 3: Fulltext Password
584             if (!CGUIDialogKeyboard::ShowAndVerifyNewPassword(strNewPW))
585               return false;
586             else strNewLockMode = "3";
587             break;
588           default:  // Not supported, abort
589             return false;
590             break;
591           }
592           bResult = true;
593         }
594         if (!bResult)
595           return false;
596                     // password ReSet and re-entry succeeded, write out the lock data
597         g_settings.BeginBookmarkTransaction();
598                     g_settings.UpdateBookmark(strType, share->strName, "lockcode", strNewPW);
599                     g_settings.UpdateBookmark(strType, share->strName, "lockmode", strNewLockMode);
600                     g_settings.UpdateBookmark(strType, share->strName, "badpwdcount", "0");
601         g_settings.CommitBookmarkTransaction();
602                     return true;
603       }
604       else if (btn == btn_Settings)
605       { 
606         if (strType == "video")
607           m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MYVIDEOS); 
608         else if (strType == "music")
609           m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MYMUSIC);
610         else if (strType == "myprograms")
611           m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MYPROGRAMS);
612         else if (strType == "pictures")
613           m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MYPICTURES);
614         else if (strType == "files")
615           m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MENU);
616         return true;
617       }
618     }
619   }
620   return false;
621 }
622
623 void CGUIDialogContextMenu::OnWindowUnload()
624 {
625   ClearButtons();
626 }
627
628 CStdString CGUIDialogContextMenu::GetDefaultShareNameByType(const CStdString &strType)
629 {
630   VECSHARES *pShares = g_settings.GetSharesFromType(strType);
631   CStdString strDefault = g_settings.GetDefaultShareFromType(strType);
632
633   if (!pShares) return "";
634
635   bool bIsBookmarkName(false);
636   int iIndex = CUtil::GetMatchingShare(strDefault, *pShares, bIsBookmarkName);
637   if (iIndex < 0)
638     return "";
639
640   return pShares->at(iIndex).strName;
641 }
642
643 void CGUIDialogContextMenu::SetDefault(const CStdString &strType, const CStdString &strDefault)
644 {
645   if (g_settings.UpDateXbmcXML(strType, "default", strDefault))
646   {
647     if (strType == "myprograms")
648       strcpy(g_stSettings.m_szDefaultPrograms, strDefault.c_str());
649     else if (strType == "files")
650       strcpy(g_stSettings.m_szDefaultFiles, strDefault.c_str());
651     else if (strType == "music")
652       strcpy(g_stSettings.m_szDefaultMusic, strDefault.c_str());
653     else if (strType == "video")
654       strcpy(g_stSettings.m_szDefaultVideos, strDefault.c_str());
655     else if (strType == "pictures")
656       strcpy(g_stSettings.m_szDefaultPictures, strDefault.c_str());
657   }
658   else
659     CLog::Log(LOGERROR, "Could not change default bookmark for %s", strType.c_str());
660 }
661
662 void CGUIDialogContextMenu::ClearDefault(const CStdString &strType)
663 {
664   SetDefault(strType, "");
665 }
666
667 void CGUIDialogContextMenu::SwitchMedia(const CStdString& strType, const CStdString& strPath, float posX, float posY)
668 {
669         // what should we display?
670         vector <CStdString> vecTypes;
671         if (!strType.Equals("music"))
672                 vecTypes.push_back(g_localizeStrings.Get(2));   // My Music
673         if (!strType.Equals("video"))
674                 vecTypes.push_back(g_localizeStrings.Get(3));   // My Videos
675         if (!strType.Equals("pictures"))
676                 vecTypes.push_back(g_localizeStrings.Get(1));   // My Pictures
677         if (!strType.Equals("files"))
678                 vecTypes.push_back(g_localizeStrings.Get(7));   // My Files
679
680         // something went wrong
681         if (vecTypes.size() != 3)
682                 return;
683
684         // create menu
685         CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU);
686   pMenu->Initialize();
687
688         // add buttons
689   int btn_Type[3];
690         for (int i=0; i<3; i++)
691         {
692                 btn_Type[i] = pMenu->AddButton(vecTypes[i]);
693         }
694
695   // display menu
696   pMenu->SetPosition(posX - pMenu->GetWidth() / 2, posY - pMenu->GetHeight() / 2);
697   pMenu->DoModal();
698
699   // check selection
700   int btn = pMenu->GetButton();
701   for (int i=0; i<3; i++)
702   {
703     if (btn == btn_Type[i])
704     {
705                         // map back to correct window
706                         int iWindow = WINDOW_INVALID;
707                         if (vecTypes[i].Equals(g_localizeStrings.Get(2)))
708                                 iWindow = WINDOW_MUSIC_FILES;
709                         else if (vecTypes[i].Equals(g_localizeStrings.Get(3)))
710                                 iWindow = WINDOW_VIDEO_FILES;
711                         else if (vecTypes[i].Equals(g_localizeStrings.Get(1)))
712                                 iWindow = WINDOW_PICTURES;
713                         else if (vecTypes[i].Equals(g_localizeStrings.Get(7)))
714                                 iWindow = WINDOW_FILES;
715
716       //m_gWindowManager.ActivateWindow(iWindow, strPath);
717       m_gWindowManager.ChangeActiveWindow(iWindow, strPath);
718                         return;
719     }
720   }
721         return;
722 }