Example #1
0
HRESULT WINAPI FileSystem::CopyToClipboard(IAIMPObjectList *Files) {
    std::string text;
    for (int i = 0, n = Files->GetCount(); i < n; ++i) {
        IAIMPString *str = nullptr;
        Files->GetObject(i, IID_IAIMPString, reinterpret_cast<void **>(&str));
        if (Config::TrackInfo *ti = Tools::TrackInfo(str)) {
            text += Tools::ToString(ti->Permalink) + "\r\n";
        }
        str->Release();
    }

    OpenClipboard(Plugin::instance()->GetMainWindowHandle());
    EmptyClipboard();
    HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, text.size() + 1);
    if (!hg) {
        CloseClipboard();
        return E_FAIL;
    }
    memcpy(GlobalLock(hg), text.c_str(), text.size() + 1);
    GlobalUnlock(hg);
    SetClipboardData(CF_TEXT, hg);
    CloseClipboard();
    GlobalFree(hg);
    return S_OK;
}
Example #2
0
std::wstring Plugin::Lang(const std::wstring &key, int part) {
    std::wstring ret;
    if (!m_muiService)
        return ret;

    IAIMPString *value = nullptr;
    if (part > -1) {
        if (SUCCEEDED(m_muiService->GetValuePart(AIMPString(key), part, &value))) {
            ret = value->GetData();
            value->Release();
        }
    } else {
        if (SUCCEEDED(m_muiService->GetValue(AIMPString(key), &value))) {
            ret = value->GetData();
            value->Release();
        }
    }
    return ret;
}
Example #3
0
IAIMPMenuItem *AimpMenu::Add(const std::wstring &name, CallbackFunc action, UINT icon, CallbackFunc showAction) {
    IAIMPMenuItem *newItem = nullptr;
    if (SUCCEEDED(m_core->CreateObject(IID_IAIMPMenuItem, reinterpret_cast<void **>(&newItem)))) {
        newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_PARENT, m_menuItem);
        newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_ID, AIMPString(L"AIMPSoundcloud" + name));

        if (action) {
            IAIMPAction *newAction = nullptr;
            if (SUCCEEDED(m_core->CreateObject(IID_IAIMPAction, reinterpret_cast<void **>(&newAction)))) {
                newAction->SetValueAsObject(AIMP_ACTION_PROPID_ID, AIMPString(L"AIMPSoundcloudAction" + name));
                newAction->SetValueAsObject(AIMP_ACTION_PROPID_GROUPNAME, AIMPString(L"SoundCloud"));
                AIMPString actionName;
                if (m_menuItem) {
                    IAIMPString *parentName;
                    if (SUCCEEDED(m_menuItem->GetValueAsObject(AIMP_MENUITEM_PROPID_NAME, IID_IAIMPString, reinterpret_cast<void **>(&parentName)))) {
                        actionName->Add(parentName);
                        parentName->Release();
                        actionName->Add2(L" -> ", 4);
                    }
                }
                actionName->Add(AIMPString(name));

                newAction->SetValueAsObject(AIMP_ACTION_PROPID_NAME, actionName);
                newAction->SetValueAsObject(AIMP_ACTION_PROPID_EVENT, new ClickHandler(action, newItem));
                newAction->SetValueAsInt32(AIMP_ACTION_PROPID_ENABLED, true);

                m_core->RegisterExtension(IID_IAIMPServiceActionManager, newAction);
                newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_ACTION, newAction);
                newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_NAME, AIMPString(name));

                newAction->Release();
            }
        } else {
            newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_ID, AIMPString(L"AIMPSoundcloud" + name));
            newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_NAME, AIMPString(name));
            newItem->SetValueAsInt32(AIMP_MENUITEM_PROPID_ENABLED, true);
        }

        if (showAction) {
            newItem->SetValueAsObject(AIMP_MENUITEM_PROPID_EVENT_ONSHOW, new ClickHandler(showAction, newItem));
        }

        if (icon > 0) {
            SetIcon(newItem, icon);
        }

        newItem->SetValueAsInt32(AIMP_MENUITEM_PROPID_STYLE, AIMP_MENUITEM_STYLE_NORMAL);
        newItem->SetValueAsInt32(AIMP_MENUITEM_PROPID_VISIBLE, true);

        m_core->RegisterExtension(IID_IAIMPServiceMenuManager, newItem);
        return newItem;
    }
    return nullptr;
}
Example #4
0
void Plugin::ForSelectedTracks(std::function<int(IAIMPPlaylist *, IAIMPPlaylistItem *, int64_t)> callback) {
    if (!callback)
        return;

    if (IAIMPPlaylist *pl = GetCurrentPlaylist()) {
        pl->BeginUpdate();
        std::set<IAIMPPlaylistItem *> to_del;
        auto delPending = [&] {
            for (auto x : to_del) {
                pl->Delete(x);
                x->Release();
            }
        };
        for (int i = 0, n = pl->GetItemCount(); i < n; ++i) {
            IAIMPPlaylistItem *item = nullptr;
            if (SUCCEEDED(pl->GetItem(i, IID_IAIMPPlaylistItem, reinterpret_cast<void **>(&item)))) {
                int isSelected = 0;
                if (SUCCEEDED(item->GetValueAsInt32(AIMP_PLAYLISTITEM_PROPID_SELECTED, &isSelected))) {
                    if (isSelected) {
                        IAIMPString *url = nullptr;
                        if (SUCCEEDED(item->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&url)))) {
                            int64_t id = Tools::TrackIdFromUrl(url->GetData());
                            url->Release();
                            
                            int result = callback(pl, item, id);
                            if (result & FLAG_DELETE_ITEM) {
                                to_del.insert(item);
                                if (result & FLAG_STOP_LOOP) {
                                    delPending();
                                    pl->EndUpdate();
                                    pl->Release();
                                    return;
                                }
                                continue;
                            }
                            if (result & FLAG_STOP_LOOP) {
                                delPending();
                                item->Release();
                                pl->EndUpdate();
                                pl->Release();
                                return;
                            }
                        }
                    }
                }
                item->Release();
            }
        }
        delPending();
        pl->EndUpdate();
        pl->Release();
    }
}
Example #5
0
std::wstring Plugin::PlaylistId(IAIMPPlaylist *pl) {
    std::wstring playlistId;
    IAIMPPropertyList *plProp = nullptr;
    if (SUCCEEDED(pl->QueryInterface(IID_IAIMPPropertyList, reinterpret_cast<void **>(&plProp)))) {
        IAIMPString *id = nullptr;
        if (SUCCEEDED(plProp->GetValueAsObject(AIMP_PLAYLIST_PROPID_ID, IID_IAIMPString, reinterpret_cast<void **>(&id)))) {
            playlistId = id->GetData();
            id->Release();
        }
        plProp->Release();
    }
    return playlistId;
}
Example #6
0
void Plugin::ForEveryItem(IAIMPPlaylist *pl, std::function<int(IAIMPPlaylistItem *, IAIMPFileInfo *, int64_t)> callback) {
    if (!pl || !callback)
        return;

    pl->BeginUpdate();
    for (int i = 0, n = pl->GetItemCount(); i < n; ++i) {
        IAIMPPlaylistItem *item = nullptr;
        if (SUCCEEDED(pl->GetItem(i, IID_IAIMPPlaylistItem, reinterpret_cast<void **>(&item)))) {
            IAIMPFileInfo *finfo = nullptr;
            if (SUCCEEDED(item->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_FILEINFO, IID_IAIMPFileInfo, reinterpret_cast<void **>(&finfo)))) {
                IAIMPString *custom = nullptr;
                if (SUCCEEDED(finfo->GetValueAsObject(AIMP_FILEINFO_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&custom)))) {
                    std::wstring url(custom->GetData());
                    custom->Release();

                    int64_t id = Tools::TrackIdFromUrl(url);
                    int result = callback(item, finfo, id);
                    if (result & FLAG_DELETE_ITEM) {
                        pl->Delete(item);
                        finfo->Release();
                        item->Release();
                        i--;
                        n--;
                        if (result & FLAG_STOP_LOOP) {
                            pl->EndUpdate();
                            return;
                        }
                        continue;
                    }
                    if (result & FLAG_STOP_LOOP) {
                        finfo->Release();
                        item->Release();
                        pl->EndUpdate();
                        return;
                    }
                }
                finfo->Release();
            }
            item->Release();
        }
    }
    pl->EndUpdate();
}
HRESULT WINAPI ArtworkProvider::Get2(IAIMPFileInfo *FileInfo, IAIMPPropertyList *Options, IAIMPImageContainer **Image) {
    if (!FileInfo || !Options || !Image)
        return E_INVALIDARG;

    IAIMPString *url = nullptr;
    if (SUCCEEDED(FileInfo->GetValueAsObject(AIMP_FILEINFO_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&url)))) {
        auto ti = Tools::TrackInfo(url);
        url->Release();
        if (ti) {
            if (!ti->Artwork.empty()) {
                int maxFileSize = 0;
                if (SUCCEEDED(Options->GetValueAsInt32(AIMP_SERVICE_ALBUMART_PROPID_FIND_IN_INTERNET_MAX_FILE_SIZE, &maxFileSize))) {
                    AimpHTTP::DownloadImage(ti->Artwork, Image, maxFileSize);
                    return *Image ? S_OK : E_FAIL;
                }
            }
        }
    }

    return E_FAIL;
}