diff --git a/src/DownloadListCtrl.cpp b/src/DownloadListCtrl.cpp index 239d25f5ca..981b25eb50 100644 --- a/src/DownloadListCtrl.cpp +++ b/src/DownloadListCtrl.cpp @@ -583,7 +583,7 @@ void CDownloadListCtrl::OnPreviewFile(wxCommandEvent &WXUNUSED(event)) ItemList files = ::GetSelectedItems(this); if (files.size() == 1) { - PreviewFile(files.front()->GetFile()); + PreviewFile(files.front()->GetFile(), this); } } @@ -592,7 +592,7 @@ void CDownloadListCtrl::OnItemActivated(wxListEvent &evt) CPartFile *file = reinterpret_cast(GetItemData(evt.GetIndex()))->GetFile(); if ((!file->IsPartFile() || file->IsCompleted()) && file->PreviewAvailable()) { - PreviewFile(file); + PreviewFile(file, this); } } @@ -1379,7 +1379,7 @@ void CDownloadListCtrl::DrawFileStatusBar( #define QUOTE "\'" #endif -void CDownloadListCtrl::PreviewFile(CPartFile *file) +void CDownloadListCtrl::PreviewFile(CKnownFile *file, wxWindow *parent) { wxString command; if (thePrefs::GetVideoPlayer().IsEmpty()) { @@ -1410,7 +1410,7 @@ void CDownloadListCtrl::PreviewFile(CPartFile *file) defaultPreview, _("File preview"), wxOK, - this); + parent); } else { command = thePrefs::GetVideoPlayer(); } @@ -1421,13 +1421,15 @@ void CDownloadListCtrl::PreviewFile(CPartFile *file) // Check if we are (pre)viewing a completed file or not if (!file->IsCompleted()) { // Remove the .met and see if out video player specifiation uses the magic string - partName = file->GetPartMetFileName().RemoveExt().GetRaw(); - partFile = thePrefs::GetTempDir().JoinPaths(file->GetPartMetFileName().RemoveExt()).GetRaw(); + CPartFile *partfile = static_cast(file); + partName = partfile->GetPartMetFileName().RemoveExt().GetRaw(); + partFile = + thePrefs::GetTempDir().JoinPaths(partfile->GetPartMetFileName().RemoveExt()).GetRaw(); } else { // This is a complete file // FIXME: This is probably not going to work if the filenames are mangled ... partName = file->GetFileName().GetRaw(); - partFile = file->GetFullName().GetRaw(); + partFile = file->GetFilePath().JoinPaths(file->GetFileName()).GetRaw(); } // Compatibility with old behaviour diff --git a/src/DownloadListCtrl.h b/src/DownloadListCtrl.h index 3e769413cf..0166ea08b4 100644 --- a/src/DownloadListCtrl.h +++ b/src/DownloadListCtrl.h @@ -33,6 +33,7 @@ #include "Constants.h" // Needed for DownloadItemType #include "MuleListCtrl.h" // Needed for CMuleListCtrl +class CKnownFile; class CPartFile; class wxBitmap; class wxRect; @@ -130,6 +131,17 @@ class CDownloadListCtrl : public CMuleListCtrl */ void DoItemSelectionChanged(); + /** + * Executes the user-selected preview command on the specified file. + * + * Works for incomplete downloads (previewing the partfile in the + * temp dir) as well as for completed/shared files. + * + * @param file The file to be previewed. + * @param parent Window used as parent for any message boxes. + */ + static void PreviewFile(CKnownFile *file, wxWindow *parent); + protected: /// Return old column order. wxString GetOldColumnOrder() const; @@ -184,13 +196,6 @@ class CDownloadListCtrl : public CMuleListCtrl void OnKeyPressed(wxKeyEvent &event); void OnItemSelectionChanged(wxListEvent &event); - /** - * Executes the user-selected preview command on the specified file. - * - * @file The file to be previewed. - */ - void PreviewFile(CPartFile *file); - /** * Show file detail dialog for item at index */ diff --git a/src/SharedFilesCtrl.cpp b/src/SharedFilesCtrl.cpp index 846f98db45..820c804222 100644 --- a/src/SharedFilesCtrl.cpp +++ b/src/SharedFilesCtrl.cpp @@ -27,21 +27,22 @@ #include -#include "muuli_wdr.h" // Needed for ID_SHFILELIST -#include "SharedFilesWnd.h" // Needed for CSharedFilesWnd -#include "amuleDlg.h" // Needed for CamuleDlg -#include "CommentDialog.h" // Needed for CCommentDialog -#include "PartFile.h" // Needed for CPartFile -#include "SharedFileList.h" // Needed for CKnownFileMap -#include "amule.h" // Needed for theApp -#include "ServerConnect.h" // Needed for CServerConnect -#include "Preferences.h" // Needed for thePrefs -#include "BarShader.h" // Needed for CBarShader -#include "DataToText.h" // Needed for PriorityToStr -#include "GuiEvents.h" // Needed for CoreNotify_* -#include "MuleCollection.h" // Needed for CMuleCollection -#include "DownloadQueue.h" // Needed for CDownloadQueue -#include "TransferWnd.h" // Needed for CTransferWnd +#include "muuli_wdr.h" // Needed for ID_SHFILELIST +#include "SharedFilesWnd.h" // Needed for CSharedFilesWnd +#include "amuleDlg.h" // Needed for CamuleDlg +#include "CommentDialog.h" // Needed for CCommentDialog +#include "PartFile.h" // Needed for CPartFile +#include "SharedFileList.h" // Needed for CKnownFileMap +#include "amule.h" // Needed for theApp +#include "ServerConnect.h" // Needed for CServerConnect +#include "Preferences.h" // Needed for thePrefs +#include "BarShader.h" // Needed for CBarShader +#include "DataToText.h" // Needed for PriorityToStr +#include "GuiEvents.h" // Needed for CoreNotify_* +#include "MuleCollection.h" // Needed for CMuleCollection +#include "DownloadQueue.h" // Needed for CDownloadQueue +#include "TransferWnd.h" // Needed for CTransferWnd +#include "DownloadListCtrl.h" // Needed for CDownloadListCtrl::PreviewFile wxBEGIN_EVENT_TABLE(CSharedFilesCtrl, CMuleListCtrl) EVT_LIST_ITEM_RIGHT_CLICK(-1, CSharedFilesCtrl::OnRightClick) @@ -66,6 +67,7 @@ wxBEGIN_EVENT_TABLE(CSharedFilesCtrl, CMuleListCtrl) EVT_MENU(MP_GETAICHED2KLINKSRC, CSharedFilesCtrl::OnCreateURI) EVT_MENU(MP_RENAME, CSharedFilesCtrl::OnRename) EVT_MENU(MP_WS, CSharedFilesCtrl::OnGetFeedback) + EVT_MENU(MP_VIEW, CSharedFilesCtrl::OnPlayFile) EVT_CHAR(CSharedFilesCtrl::OnKeyPressed) wxEND_EVENT_TABLE() @@ -127,6 +129,10 @@ void CSharedFilesCtrl::OnRightClick(wxListEvent &event) if ((m_menu == NULL) && (item_hit != -1)) { m_menu = new wxMenu(_("Shared Files")); + + m_menu->Append(MP_VIEW, _("&Play")); + m_menu->AppendSeparator(); + wxMenu *prioMenu = new wxMenu(); prioMenu->AppendCheckItem(MP_PRIOVERYLOW, _("Very low")); prioMenu->AppendCheckItem(MP_PRIOLOW, _("Low")); @@ -166,6 +172,11 @@ void CSharedFilesCtrl::OnRightClick(wxListEvent &event) m_menu->Append(MP_GETAICHED2KLINKSRC, _("Copy eD2k link to clipboard (&AICH info + Source)")); m_menu->Append(MP_WS, _("Copy feedback to clipboard")); + // Incomplete files shared while downloading can only be played + // if enough of the beginning has been downloaded. + m_menu->Enable( + MP_VIEW, file->IsCompleted() || static_cast(file)->PreviewAvailable()); + m_menu->Enable(MP_GETAICHED2KLINK, file->HasProperAICHHashSet()); m_menu->Enable(MP_GETAICHED2KLINKSRC, file->HasProperAICHHashSet()); m_menu->Enable(MP_GETHOSTNAMESOURCEED2KLINK, !thePrefs::GetYourHostname().IsEmpty()); @@ -764,6 +775,15 @@ void CSharedFilesCtrl::OnKeyPressed(wxKeyEvent &event) event.Skip(); } +void CSharedFilesCtrl::OnPlayFile(wxCommandEvent &WXUNUSED(event)) +{ + if (GetSelectedItemCount() == 1) { + long index = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + + CDownloadListCtrl::PreviewFile(reinterpret_cast(GetItemData(index)), this); + } +} + void CSharedFilesCtrl::OnAddCollection(wxCommandEvent &WXUNUSED(evt)) { int item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); diff --git a/src/SharedFilesCtrl.h b/src/SharedFilesCtrl.h index 4e71588524..3906906c1a 100644 --- a/src/SharedFilesCtrl.h +++ b/src/SharedFilesCtrl.h @@ -190,6 +190,11 @@ class CSharedFilesCtrl : public CMuleListCtrl */ void OnAddCollection(wxCommandEvent &WXUNUSED(evt)); + /** + * Event-handler for the Play menu item. + */ + void OnPlayFile(wxCommandEvent &event); + //! Pointer used to ensure that the menu isn't displayed twice. wxMenu *m_menu;