Example #1
0
void CAnnouncementManager::Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item, CVariant &data)
{
  if (!item.get())
  {
    Announce(flag, sender, message, data);
    return;
  }

  // Extract db id of item
  CVariant object = data.isNull() || data.isObject() ? data : CVariant::VariantTypeObject;
  std::string type;
  int id = 0;
  
  if(item->HasPVRChannelInfoTag())
  {
    const PVR::CPVRChannelPtr channel(item->GetPVRChannelInfoTag());
    id = channel->ChannelID();
    type = "channel";

    object["item"]["title"] = channel->ChannelName();
    object["item"]["channeltype"] = channel->IsRadio() ? "radio" : "tv";

    if (data.isMember("player") && data["player"].isMember("playerid"))
      object["player"]["playerid"] = channel->IsRadio() ? PLAYLIST_MUSIC : PLAYLIST_VIDEO;
  }
  else if (item->HasVideoInfoTag())
  {
    id = item->GetVideoInfoTag()->m_iDbId;

    // TODO: Can be removed once this is properly handled when starting playback of a file
    if (id <= 0 && !item->GetPath().empty() &&
       (!item->HasProperty(LOOKUP_PROPERTY) || item->GetProperty(LOOKUP_PROPERTY).asBoolean()))
    {
      CVideoDatabase videodatabase;
      if (videodatabase.Open())
      {
        std::string path = item->GetPath();
        std::string videoInfoTagPath(item->GetVideoInfoTag()->m_strFileNameAndPath);
        if (StringUtils::StartsWith(videoInfoTagPath, "removable://"))
          path = videoInfoTagPath;
        if (videodatabase.LoadVideoInfo(path, *item->GetVideoInfoTag(), VideoDbDetailsNone))
          id = item->GetVideoInfoTag()->m_iDbId;

        videodatabase.Close();
      }
    }

    if (!item->GetVideoInfoTag()->m_type.empty())
      type = item->GetVideoInfoTag()->m_type;
    else
      CVideoDatabase::VideoContentTypeToString((VIDEODB_CONTENT_TYPE)item->GetVideoContentType(), type);

    if (id <= 0)
    {
      // TODO: Can be removed once this is properly handled when starting playback of a file
      item->SetProperty(LOOKUP_PROPERTY, false);

      std::string title = item->GetVideoInfoTag()->m_strTitle;
      if (title.empty())
        title = item->GetLabel();
      object["item"]["title"] = title;

      switch (item->GetVideoContentType())
      {
      case VIDEODB_CONTENT_MOVIES:
        if (item->GetVideoInfoTag()->m_iYear > 0)
          object["item"]["year"] = item->GetVideoInfoTag()->m_iYear;
        break;
      case VIDEODB_CONTENT_EPISODES:
        if (item->GetVideoInfoTag()->m_iEpisode >= 0)
          object["item"]["episode"] = item->GetVideoInfoTag()->m_iEpisode;
        if (item->GetVideoInfoTag()->m_iSeason >= 0)
          object["item"]["season"] = item->GetVideoInfoTag()->m_iSeason;
        if (!item->GetVideoInfoTag()->m_strShowTitle.empty())
          object["item"]["showtitle"] = item->GetVideoInfoTag()->m_strShowTitle;
        break;
      case VIDEODB_CONTENT_MUSICVIDEOS:
        if (!item->GetVideoInfoTag()->m_strAlbum.empty())
          object["item"]["album"] = item->GetVideoInfoTag()->m_strAlbum;
        if (!item->GetVideoInfoTag()->m_artist.empty())
          object["item"]["artist"] = StringUtils::Join(item->GetVideoInfoTag()->m_artist, " / ");
        break;
      }
    }
  }
  else if (item->HasMusicInfoTag())
  {
    id = item->GetMusicInfoTag()->GetDatabaseId();
    type = MediaTypeSong;

    // TODO: Can be removed once this is properly handled when starting playback of a file
    if (id <= 0 && !item->GetPath().empty() &&
       (!item->HasProperty(LOOKUP_PROPERTY) || item->GetProperty(LOOKUP_PROPERTY).asBoolean()))
    {
      CMusicDatabase musicdatabase;
      if (musicdatabase.Open())
      {
        CSong song;
        if (musicdatabase.GetSongByFileName(item->GetPath(), song, item->m_lStartOffset))
        {
          item->GetMusicInfoTag()->SetSong(song);
          id = item->GetMusicInfoTag()->GetDatabaseId();
        }

        musicdatabase.Close();
      }
    }

    if (id <= 0)
    {
      // TODO: Can be removed once this is properly handled when starting playback of a file
      item->SetProperty(LOOKUP_PROPERTY, false);

      std::string title = item->GetMusicInfoTag()->GetTitle();
      if (title.empty())
        title = item->GetLabel();
      object["item"]["title"] = title;

      if (item->GetMusicInfoTag()->GetTrackNumber() > 0)
        object["item"]["track"] = item->GetMusicInfoTag()->GetTrackNumber();
      if (!item->GetMusicInfoTag()->GetAlbum().empty())
        object["item"]["album"] = item->GetMusicInfoTag()->GetAlbum();
      if (!item->GetMusicInfoTag()->GetArtist().empty())
        object["item"]["artist"] = item->GetMusicInfoTag()->GetArtist();
    }
  }
  else if (item->IsVideo())
  {
    // video item but has no video info tag.
    type = "movies";
    object["item"]["title"] = item->GetLabel();
  }
  else if (item->HasPictureInfoTag())
  {
    type = "picture";
    object["item"]["file"] = item->GetPath();
  }
  else
    type = "unknown";

  object["item"]["type"] = type;
  if (id > 0)
    object["item"]["id"] = id;

  Announce(flag, sender, message, object);
}
Example #2
0
bool CGUIControlListSetting::OnClick()
{
  if (m_pButton == NULL)
    return false;

  CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  if (dialog == NULL)
    return false;

  CFileItemList options;
  if (!GetItems(m_pSetting, options) || options.Size() <= 1)
    return false;

  const CSettingControlList *control = static_cast<const CSettingControlList*>(m_pSetting->GetControl());
  
  dialog->Reset();
  dialog->SetHeading(g_localizeStrings.Get(m_pSetting->GetLabel()));
  dialog->SetItems(&options);
  dialog->SetMultiSelection(control->CanMultiSelect());
  dialog->DoModal();

  if (!dialog->IsConfirmed())
    return false;

  const CFileItemList &items = dialog->GetSelectedItems();
  std::vector<CVariant> values;
  for (int index = 0; index < items.Size(); index++)
  {
    const CFileItemPtr item = items[index];
    if (item == NULL || !item->HasProperty("value"))
      return false;

    values.push_back(item->GetProperty("value"));
  }

  bool ret = false;
  switch (m_pSetting->GetType())
  {
    case SettingTypeInteger:
      if (values.size() > 1)
        return false;
      ret = ((CSettingInt *)m_pSetting)->SetValue((int)values.at(0).asInteger());
      break;

    case SettingTypeString:
      if (values.size() > 1)
        return false;
      ret = ((CSettingString *)m_pSetting)->SetValue(values.at(0).asString());
      break;

    case SettingTypeList:
      ret = CSettings::Get().SetList(m_pSetting->GetId(), values);
      break;
    
    default:
      break;
  }

  if (ret)
    Update();

  return ret;
}
Example #3
0
void CAnnouncementManager::Announce(AnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item, CVariant &data)
{
    if (!item.get())
    {
        Announce(flag, sender, message, data);
        return;
    }

    // Extract db id of item
    CVariant object = data.isNull() || data.isObject() ? data : CVariant::VariantTypeObject;
    CStdString type;
    int id = 0;

    if (item->HasVideoInfoTag())
    {
        id = item->GetVideoInfoTag()->m_iDbId;

        // TODO: Can be removed once this is properly handled when starting playback of a file
        if (id <= 0 && !item->GetPath().empty() &&
                (!item->HasProperty(LOOKUP_PROPERTY) || item->GetProperty(LOOKUP_PROPERTY).asBoolean()))
        {
            CVideoDatabase videodatabase;
            if (videodatabase.Open())
            {
                if (videodatabase.LoadVideoInfo(item->GetPath(), *item->GetVideoInfoTag()))
                    id = item->GetVideoInfoTag()->m_iDbId;

                videodatabase.Close();
            }
        }

        CVideoDatabase::VideoContentTypeToString((VIDEODB_CONTENT_TYPE)item->GetVideoContentType(), type);

        if (id <= 0)
        {
            // TODO: Can be removed once this is properly handled when starting playback of a file
            item->SetProperty(LOOKUP_PROPERTY, false);

            object["title"] = item->GetVideoInfoTag()->m_strTitle;

            switch (item->GetVideoContentType())
            {
            case VIDEODB_CONTENT_MOVIES:
                if (item->GetVideoInfoTag()->m_iYear > 0)
                    object["year"] = item->GetVideoInfoTag()->m_iYear;
                break;
            case VIDEODB_CONTENT_EPISODES:
                if (item->GetVideoInfoTag()->m_iEpisode >= 0)
                    object["episode"] = item->GetVideoInfoTag()->m_iEpisode;
                if (item->GetVideoInfoTag()->m_iSeason >= 0)
                    object["season"] = item->GetVideoInfoTag()->m_iSeason;
                if (!item->GetVideoInfoTag()->m_strShowTitle.empty())
                    object["showtitle"] = item->GetVideoInfoTag()->m_strShowTitle;
                break;
            case VIDEODB_CONTENT_MUSICVIDEOS:
                if (!item->GetVideoInfoTag()->m_strAlbum.empty())
                    object["album"] = item->GetVideoInfoTag()->m_strAlbum;
                if (!item->GetVideoInfoTag()->m_artist.empty())
                    object["artist"] = StringUtils::Join(item->GetVideoInfoTag()->m_artist, " / ");
                break;
            }
        }
    }
    else if (item->HasMusicInfoTag())
    {
        id = item->GetMusicInfoTag()->GetDatabaseId();
        type = "song";

        // TODO: Can be removed once this is properly handled when starting playback of a file
        if (id <= 0 && !item->GetPath().empty() &&
                (!item->HasProperty(LOOKUP_PROPERTY) || item->GetProperty(LOOKUP_PROPERTY).asBoolean()))
        {
            CMusicDatabase musicdatabase;
            if (musicdatabase.Open())
            {
                CSong song;
                if (musicdatabase.GetSongByFileName(item->GetPath(), song))
                {
                    item->GetMusicInfoTag()->SetSong(song);
                    item->SetMusicThumb();
                    id = item->GetMusicInfoTag()->GetDatabaseId();
                }

                musicdatabase.Close();
            }
        }

        if (id <= 0)
        {
            // TODO: Can be removed once this is properly handled when starting playback of a file
            item->SetProperty(LOOKUP_PROPERTY, false);

            object["title"] = item->GetMusicInfoTag()->GetTitle();

            if (item->GetMusicInfoTag()->GetTrackNumber() > 0)
                object["track"] = item->GetMusicInfoTag()->GetTrackNumber();
            if (!item->GetMusicInfoTag()->GetAlbum().empty())
                object["album"] = item->GetMusicInfoTag()->GetAlbum();
            if (!item->GetMusicInfoTag()->GetArtist().empty())
                object["artist"] = item->GetMusicInfoTag()->GetArtist();
        }
    }
    else
        type = "unknown";

    object["item"]["type"] = type;
    if (id > 0)
        object["item"]["id"] = id;

    Announce(flag, sender, message, object);
}
Example #4
0
bool CFileItemHandler::GetField(const std::string &field, const CVariant &info, const CFileItemPtr &item, CVariant &result, bool &fetchedArt, CThumbLoader *thumbLoader /* = NULL */)
{
  if (result.isMember(field) && !result[field].empty())
    return true;

  if (info.isMember(field) && !info[field].isNull())
  {
    result[field] = info[field];
    return true;
  }

  if (item)
  {
    if (item->IsAlbum())
    {
      if (field == "albumlabel")
      {
        result[field] = item->GetProperty("album_label");
        return true;
      }
      if (item->HasProperty("album_" + field + "_array"))
      {
        result[field] = item->GetProperty("album_" + field + "_array");
        return true;
      }
      if (item->HasProperty("album_" + field))
      {
        result[field] = item->GetProperty("album_" + field);
        return true;
      }
    }
    
    if (item->HasProperty("artist_" + field + "_array"))
    {
      result[field] = item->GetProperty("artist_" + field + "_array");
      return true;
    }
    if (item->HasProperty("artist_" + field))
    {
      result[field] = item->GetProperty("artist_" + field);
      return true;
    }

    if (field == "art")
    {
      if (thumbLoader != NULL && item->GetArt().size() <= 0 && !fetchedArt &&
        ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1)))
      {
        thumbLoader->FillLibraryArt(*item);
        fetchedArt = true;
      }

      CGUIListItem::ArtMap artMap = item->GetArt();
      CVariant artObj(CVariant::VariantTypeObject);
      for (CGUIListItem::ArtMap::const_iterator artIt = artMap.begin(); artIt != artMap.end(); artIt++)
      {
        if (!artIt->second.empty())
          artObj[artIt->first] = CTextureCache::GetWrappedImageURL(artIt->second);
      }

      result["art"] = artObj;
      return true;
    }
    
    if (field == "thumbnail")
    {
      if (thumbLoader != NULL && !item->HasArt("thumb") && !fetchedArt &&
        ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1)))
      {
        thumbLoader->FillLibraryArt(*item);
        fetchedArt = true;
      }
      else if (item->HasPictureInfoTag() && !item->HasArt("thumb"))
        item->SetArt("thumb", CTextureCache::GetWrappedThumbURL(item->GetPath()));
      
      if (item->HasArt("thumb"))
        result["thumbnail"] = CTextureCache::GetWrappedImageURL(item->GetArt("thumb"));
      else
        result["thumbnail"] = "";
      
      return true;
    }
    
    if (field == "fanart")
    {
      if (thumbLoader != NULL && !item->HasArt("fanart") && !fetchedArt &&
        ((item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iDbId > -1) || (item->HasMusicInfoTag() && item->GetMusicInfoTag()->GetDatabaseId() > -1)))
      {
        thumbLoader->FillLibraryArt(*item);
        fetchedArt = true;
      }
      
      if (item->HasArt("fanart"))
        result["fanart"] = CTextureCache::GetWrappedImageURL(item->GetArt("fanart"));
      else
        result["fanart"] = "";
      
      return true;
    }
    
    if (item->HasVideoInfoTag() && item->GetVideoContentType() == VIDEODB_CONTENT_TVSHOWS)
    {
      if (item->GetVideoInfoTag()->m_iSeason < 0 && field == "season")
      {
        result[field] = (int)item->GetProperty("totalseasons").asInteger();
        return true;
      }
      if (field == "watchedepisodes")
      {
        result[field] = (int)item->GetProperty("watchedepisodes").asInteger();
        return true;
      }
    }
    
    if (field == "lastmodified" && item->m_dateTime.IsValid())
    {
      result[field] = item->m_dateTime.GetAsLocalizedDateTime();
      return true;
    }
  }

  return false;
}
Example #5
0
void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const CVariant& fields, CVariant &result)
{
  if (info == NULL || fields.size() == 0)
    return;

  CVariant serialization;
  info->Serialize(serialization);

  bool fetchedArt = false;

  for (unsigned int i = 0; i < fields.size(); i++)
  {
    CStdString field = fields[i].asString();

    if (item)
    {
      if (item->IsAlbum() && field.Equals("albumlabel"))
        field = "label";
      if (item->IsAlbum())
      {
        if (field == "label")
        {
          result["albumlabel"] = item->GetProperty("album_label");
          continue;
        }
        if (item->HasProperty("album_" + field + "_array"))
        {
          result[field] = item->GetProperty("album_" + field + "_array");
          continue;
        }
        if (item->HasProperty("album_" + field))
        {
          result[field] = item->GetProperty("album_" + field);
          continue;
        }
      }

      if (item->HasProperty("artist_" + field + "_array"))
      {
        result[field] = item->GetProperty("artist_" + field + "_array");
        continue;
      }
      if (item->HasProperty("artist_" + field))
      {
        result[field] = item->GetProperty("artist_" + field);
        continue;
      }

      if (field == "thumbnail")
      {
        if (item->HasVideoInfoTag())
        {
          if (!item->HasThumbnail() && !fetchedArt && item->GetVideoInfoTag()->m_iDbId > -1)
          {
            CVideoThumbLoader loader;
            loader.FillLibraryArt(item.get());
            fetchedArt = true;
          }
        }
        else if (item->HasPictureInfoTag())
        {
          if (!item->HasThumbnail())
            item->SetThumbnailImage(CTextureCache::GetWrappedThumbURL(item->GetPath()));
        }
        else if (item->HasMusicInfoTag())
        {
          if (!item->HasThumbnail() && !fetchedArt && item->GetMusicInfoTag()->GetDatabaseId() > -1)
          {
            CMusicThumbLoader loader;
            loader.FillLibraryArt(*item);
            fetchedArt = true;
          }
        }
        if (item->HasThumbnail())
          result["thumbnail"] = CTextureCache::GetWrappedImageURL(item->GetThumbnailImage());
        if (!result.isMember("thumbnail"))
          result["thumbnail"] = "";
        continue;
      }

      if (field == "fanart")
      {
        if (item->HasVideoInfoTag())
        {
          if (!item->HasProperty("fanart_image") && !fetchedArt && item->GetVideoInfoTag()->m_iDbId > -1)
          {
            CVideoThumbLoader loader;
            loader.FillLibraryArt(item.get());
            fetchedArt = true;
          }
          if (item->HasProperty("fanart_image"))
            result["fanart"] = CTextureCache::GetWrappedImageURL(item->GetProperty("fanart_image").asString());
        }
        else if (item->HasMusicInfoTag())
        {
          if (!item->HasProperty("fanart_image") && !fetchedArt && item->GetMusicInfoTag()->GetDatabaseId() > -1)
          {
            CMusicThumbLoader loader;
            loader.FillLibraryArt(*item);
            fetchedArt = true;
          }
          if (item->HasProperty("fanart_image"))
            result["fanart"] = CTextureCache::GetWrappedImageURL(item->GetProperty("fanart_image").asString());
        }
        if (!result.isMember("fanart"))
          result["fanart"] = "";
        continue;
      }

      if (item->HasVideoInfoTag() && item->GetVideoContentType() == VIDEODB_CONTENT_TVSHOWS)
      {
        if (item->GetVideoInfoTag()->m_iSeason < 0 && field == "season")
        {
          result[field] = (int)item->GetProperty("totalseasons").asInteger();
          continue;
        }
        if (field == "watchedepisodes")
        {
          result[field] = (int)item->GetProperty("watchedepisodes").asInteger();
          continue;
        }
      }

      if (field == "lastmodified" && item->m_dateTime.IsValid())
      {
        result[field] = item->m_dateTime.GetAsLocalizedDateTime();
        continue;
      }
    }

    if (serialization.isMember(field) && (!result.isMember(field) || result[field].empty()))
      result[field] = serialization[field];
  }
}
Example #6
0
void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const CVariant& fields, CVariant &result)
{
  if (info == NULL || fields.size() == 0)
    return;

  CVariant serialization;
  info->Serialize(serialization);

  for (unsigned int i = 0; i < fields.size(); i++)
  {
    CStdString field = fields[i].asString();

    if (item)
    {
      if (item->IsAlbum() && field.Equals("albumlabel"))
        field = "label";
      if (item->IsAlbum())
      {
        if (field == "label")
        {
          result["albumlabel"] = item->GetProperty("album_label");
          continue;
        }
        /* This would break backwards compatibility to JSON-RPC API v4
        if (item->HasProperty("album_" + field + "_array"))
        {
          result[field] = item->GetProperty("album_" + field + "_array");
          continue;
        }*/
        if (item->HasProperty("album_" + field))
        {
          result[field] = item->GetProperty("album_" + field);
          continue;
        }
      }

      /* This would break backwards compatibility to JSON-RPC API v4
      if (item->HasProperty("artist_" + field + "_array"))
      {
        result[field] = item->GetProperty("artist_" + field + "_array");
        continue;
      }*/
      if (item->HasProperty("artist_" + field))
      {
        result[field] = item->GetProperty("artist_" + field);
        continue;
      }

      if (field == "fanart" && !item->HasPictureInfoTag())
      {
        CStdString fanart;
        if (item->HasProperty("fanart_image"))
          fanart = CTextureCache::Get().CheckAndCacheImage(item->GetProperty("fanart_image").asString());
        if (fanart.empty())
          fanart = item->GetCachedFanart();
        if (!fanart.empty())
          result["fanart"] = fanart.c_str();

        continue;
      }

      if (item->HasVideoInfoTag() && item->GetVideoContentType() == VIDEODB_CONTENT_TVSHOWS)
      {
        if (item->GetVideoInfoTag()->m_iSeason < 0 && field == "season")
        {
          result[field] = (int)item->GetProperty("totalseasons").asInteger();
          continue;
        }
        if (field == "watchedepisodes")
        {
          result[field] = (int)item->GetProperty("watchedepisodes").asInteger();
          continue;
        }
      }

      if (field == "lastmodified" && item->m_dateTime.IsValid())
      {
        result[field] = item->m_dateTime.GetAsLocalizedDateTime();
        continue;
      }
    }

    if (serialization.isMember(field) && (!result.isMember(field) || result[field].empty()))
      result[field] = serialization[field];
  }
}