Exemple #1
0
Feed *RSSParser::ParseFeed(const char *url, const char *data, int32 length) {
	Feed *feed = NULL;
	Channel *channel = NULL;
	xmlDocPtr doc = xmlParseMemory(data, length);
	if (doc == NULL) return feed;

	xmlXPathContextPtr pathCtxt = xmlXPathNewContext(doc);
	if (pathCtxt != NULL) {
		xmlXPathObjectPtr root = xmlXPathEvalExpression((const xmlChar *)"/rss/channel", pathCtxt);
	
		if (root != NULL) {			
			xmlNodeSetPtr channels = root->nodesetval;
			
			if (channels != NULL) {
				feed = new Feed(url);
				channel = new Channel();
				feed->AddChannel(channel);

				for (int32 i = 0; i < channels->nodeNr; i++) {
					xmlNode *n = channels->nodeTab[i]->children;

					while (n != NULL) {
						if (n->type == XML_ELEMENT_NODE) {
							ExtractChannelNodeDetails(channel, n);
						};
						n = n->next;
					};
				};
			};
			
			xmlXPathFreeObject(root);
		};
	};

	xmlXPathFreeContext(pathCtxt);
	
	return feed;
};
bool
ViewDrawingArea::on_button_press_event (GdkEventButton *event)
{
#ifdef DEBUG
std::cerr << "ButtonEvent y = " << event->y << std::endl << std::flush;
#endif
	
	Feed *feed = AppContext::get().get_feed();
	if (feed == NULL)
		return true;
	
	Gtk::Allocation allocation = get_allocation();
	const int height = allocation.get_height();
	const item_list_t items = feed->get_items();
	item_list_t::const_iterator it = items.begin(); 
	for (; it != items.end(); ++it)
		if ((*it) == _top_item)
			break;
	double y = _topitem_y;
	for (; it != items.end() && y < height; ++it)
	{
		ItemDisplayUnit *du = (*it)->get_display_unit();
		y += du->get_height();
		if (event->y < y)
			break;
	}

	AppContext::get().set_curr_item (*it);
	_vadj->set_value (0.0);
	(*it)->reset_display_unit();

#ifdef DEBUG
if (it!=items.end())std::cerr << "Clicked: " << conv((*it)->_title) << std::endl << std::flush;
#endif

	return true;
}
Exemple #3
0
LRESULT TorrentDialog::OnNotify(int idCtrl, LPNMHDR pnmh) {
  Feed* feed = Aggregator.Get(kFeedCategoryLink);
  if (!feed)
    return 0;

  // ListView control
  if (idCtrl == IDC_LIST_TORRENT) {
    switch (pnmh->code) {
      // Column click
      case LVN_COLUMNCLICK: {
        LPNMLISTVIEW lplv = (LPNMLISTVIEW)pnmh;
        int order = 1;
        if (lplv->iSubItem == list_.GetSortColumn()) order = list_.GetSortOrder() * -1;
        switch (lplv->iSubItem) {
          // Episode
          case 1:
            list_.Sort(lplv->iSubItem, order, ui::kListSortNumber, ui::ListViewCompareProc);
            break;
          // File size
          case 3:
            list_.Sort(lplv->iSubItem, order, ui::kListSortFileSize, ui::ListViewCompareProc);
            break;
          // Other columns
          default:
            list_.Sort(lplv->iSubItem, order, ui::kListSortDefault, ui::ListViewCompareProc);
            break;
        }
        break;
      }

      // Check/uncheck
      case LVN_ITEMCHANGED: {
        if (!list_.IsVisible()) break;
        LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(pnmh);
        if (pnmv->uOldState != 0 && (pnmv->uNewState == 0x1000 || pnmv->uNewState == 0x2000)) {
          int checked_count = 0;
          for (int i = 0; i < list_.GetItemCount(); i++) {
            if (list_.GetCheckState(i)) checked_count++;
          }
          if (checked_count == 1) {
            DlgMain.ChangeStatus(L"Marked 1 torrent.");
          } else {
            DlgMain.ChangeStatus(L"Marked " + ToWstr(checked_count) + L" torrents.");
          }
          FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(pnmv->iItem));
          if (feed_item) {
            bool checked = list_.GetCheckState(pnmv->iItem) == TRUE;
            feed_item->state = checked ? kFeedItemSelected : kFeedItemDiscardedNormal;
          }
        }
        break;
      }

      // Double click
      case NM_DBLCLK: {
        if (list_.GetSelectedCount() > 0) {
          LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh);
          if (lpnmitem->iItem == -1) break;
          FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem));
          if (feed_item)
            feed->Download(feed_item->index);
        }
        break;
      }

      // Right click
      case NM_RCLICK: {
        LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh);
        if (lpnmitem->iItem == -1) break;
        FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem));
        if (feed_item) {
          std::wstring answer = ui::Menus.Show(GetWindowHandle(), 0, 0, L"TorrentListRightClick");
          if (answer == L"DownloadTorrent") {
            feed->Download(feed_item->index);
          } else if (answer == L"Info") {
            auto anime_id = feed_item->episode_data.anime_id;
            if (anime_id) {
              ShowDlgAnimeInfo(anime_id);
            } else {
              ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")");
            }
          } else if (answer == L"DiscardTorrent") {
            feed_item->state = kFeedItemDiscardedNormal;
            list_.SetCheckState(lpnmitem->iItem, FALSE);
            Aggregator.file_archive.push_back(feed_item->title);
          } else if (answer == L"DiscardTorrents") {
            auto anime_item = AnimeDatabase.FindItem(feed_item->episode_data.anime_id);
            if (anime_item) {
              for (int i = 0; i < list_.GetItemCount(); i++) {
                feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i));
                if (feed_item && feed_item->episode_data.anime_id == anime_item->GetId()) {
                  feed_item->state = kFeedItemDiscardedNormal;
                  list_.SetCheckState(i, FALSE);
                }
              }
              Aggregator.filter_manager.AddFilter(
                  kFeedFilterActionDiscard, kFeedFilterMatchAll, kFeedFilterOptionDefault,
                  true, L"Discard \"" + anime_item->GetTitle() + L"\"");
              Aggregator.filter_manager.filters.back().AddCondition(
                  kFeedFilterElement_Meta_Id, kFeedFilterOperator_Equals,
                  ToWstr(anime_item->GetId()));
            }
          } else if (answer == L"SelectFansub") {
            int anime_id = feed_item->episode_data.anime_id;
            std::wstring group_name = feed_item->episode_data.group;
            if (anime::IsValidId(anime_id) && !group_name.empty()) {
              for (int i = 0; i < list_.GetItemCount(); i++) {
                feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i));
                if (feed_item && !IsEqual(feed_item->episode_data.group, group_name)) {
                  feed_item->state = kFeedItemDiscardedNormal;
                  list_.SetCheckState(i, FALSE);
                }
              }
              anime::SetFansubFilter(anime_id, group_name);
            }
          } else if (answer == L"MoreTorrents") {
            Search(Settings[taiga::kTorrent_Discovery_SearchUrl], feed_item->episode_data.title);
          } else if (answer == L"SearchService") {
            ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")");
          }
        }
        break;
      }

      // Custom draw
      case NM_CUSTOMDRAW: {
        LPNMLVCUSTOMDRAW pCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pnmh);
        switch (pCD->nmcd.dwDrawStage) {
          case CDDS_PREPAINT:
            return CDRF_NOTIFYITEMDRAW;
          case CDDS_ITEMPREPAINT:
            return CDRF_NOTIFYSUBITEMDRAW;
          case CDDS_PREERASE:
          case CDDS_ITEMPREERASE:
            return CDRF_NOTIFYPOSTERASE;

          case CDDS_ITEMPREPAINT | CDDS_SUBITEM: {
            // Alternate background color
            if ((pCD->nmcd.dwItemSpec % 2) && !list_.IsGroupViewEnabled())
              pCD->clrTextBk = ChangeColorBrightness(GetSysColor(COLOR_WINDOW), -0.03f);
            FeedItem* feed_item = reinterpret_cast<FeedItem*>(pCD->nmcd.lItemlParam);
            if (feed_item) {
              if (Taiga.debug_mode) {
                // Change background color
                switch (feed_item->state) {
                  case kFeedItemDiscardedNormal:
                  case kFeedItemDiscardedInactive:
                  case kFeedItemDiscardedHidden:
                    pCD->clrTextBk = ui::kColorLightRed;
                    break;
                  case kFeedItemSelected:
                    pCD->clrTextBk = ui::kColorLightGreen;
                    break;
                  default:
                    pCD->clrTextBk = GetSysColor(COLOR_WINDOW);
                    break;
                }
              }
              // Change text color
              if (feed_item->state == kFeedItemDiscardedInactive) {
                pCD->clrText = GetSysColor(COLOR_GRAYTEXT);
              } else if (feed_item->episode_data.new_episode) {
                pCD->clrText = GetSysColor(pCD->iSubItem == 1 ? COLOR_HIGHLIGHT : COLOR_WINDOWTEXT);
              }
            }
            return CDRF_NOTIFYPOSTPAINT;
          }
        }
      }
    }
  }

  return 0;
}
void 
ViewDrawingArea::draw_buffer()
{
#ifdef DEBUG
std::cerr << "VA->val:"<<_vadj->get_value() <<" VA->upper:"<<_vadj->get_upper() << std::endl << std::flush;
#endif

	Feed *feed = AppContext::get().get_feed();
	if (feed == NULL) 
		return;

	if (AppContext::get().get_display_type() == FULL)
	{
		render_full_article();
		return;
	}

	// Dimensions of drawing area
	Gtk::Allocation allocation = get_allocation();
	const int width = allocation.get_width();
	const int height = allocation.get_height();

	// First determine start item
	Cairo::RefPtr<Cairo::Context> cr = _pixmap->create_cairo_context();

#ifdef DEBUG
	/// This code was meant to investigate the 500ms delay with pango
	/// at start of rendering.
	if (!_layout_prepared)
	{
Glib::Timer sw;
sw.start();
		Glib::RefPtr<Pango::Layout> pl = Pango::Layout::create (cr);
		const char *fonts[] = {"Sans 10", "Sans 14"};
		for (unsigned i = 0; i < sizeof(fonts)/sizeof(const char*); ++i)
		{
			Pango::FontDescription fdesc (fonts[i]);
			pl->set_font_description (fdesc);
			pl->set_width (10 * Pango::SCALE); // force line break
			pl->set_markup ("<b>Show Us Your Freaky Geek Costumes</b>\nHitting the streets in a scary, tech-themed outfit this Halloween? We want to see it. Find out how your Sergey Brin costume (or is it David Duchovny?) could be featured on Wired News. test\n test");
			Pango::Rectangle irect, lrect;
			pl->get_extents (irect, lrect);
		}
		_layout_prepared = true;
sw.stop();
unsigned long l;
sw.elapsed(l);
std::cerr << "Time spent rendering: " << l << " us" << std::endl << std::flush;
	}
#endif

	const item_list_t items = feed->get_items();
	item_list_t::const_iterator start_item;
	const int n_items = items.size();
	double y = 0.0;

	if (n_items == 0)
		start_item = items.end();
	else
	{
		// Set start_item and h
		int start = static_cast<int> (_vadj->get_value());
		double h = 0.0;
		if (_vadj->get_value() > 0 && _vadj->get_value() == _vadj->get_upper())
		{
			// This will give a blank page when pulling the handle
			// full down. While unusual, it might make sense with
			// an ever-growing newslist.
			y = 0.0;
			start_item = items.end();
		}
		else
		{
			start_item = items.begin();
			for (int i = 0; i < start; ++i)
				++start_item;
			if (start < 0)
				start = 0;

			double prop = _vadj->get_value() - start;
			if (prop > 0.0)
			{
				(*start_item)->make_display_unit();
				ItemDisplayUnit *du = (*start_item)->get_display_unit();
				du->layout (cr);
				h = du->get_height();
			}
			y = - h * prop;
#ifdef DEBUG
std::cerr << "prop:"<<prop <<" y:"<<y << std::endl << std::flush;
#endif

		}
	}

	// clip to the area indicated by the expose event so that we only redraw
	// the portion of the window that needs to be redrawn
	cr->reset_clip();
	cr->rectangle (0.0, 0.0, width, height);
	cr->clip();

	// Black on white
	cr->set_source_rgb (1.0, 1.0, 1.0);
	cr->paint();
	cr->set_source_rgb (0.0, 0.0, 0.0);

	// Render text
	item_list_t::const_iterator it = start_item;
	_top_item = *start_item;
	_topitem_y = y;
	int count = 0;
	for (; it != items.end() && y < height; ++it, ++count)
	{
		(*it)->make_display_unit();
		ItemDisplayUnit *du = (*it)->get_display_unit();
		du->render (cr, 0, y);
		y += du->get_height();
	}

	cr->show_page();

	// Scrollbar settings can now be specified
	_vadj->set_upper (n_items);
	//_vadj->set_page_size (count - 1 + );
	_vadj->set_step_increment (1);
	_vadj->set_page_increment (count);
	_vadj->changed();

}
Exemple #5
0
Provider ProviderHandler::deserializeElement(const QDomElement& providerxml)
{
    Provider provider;
    KTranslatable name;

    if (providerxml.tagName() != "provider") return provider;

    QString uploadurl = providerxml.attribute("uploadurl");
    QString nouploadurl = providerxml.attribute("nouploadurl");
    QString webservice = providerxml.attribute("webservice");
    QString webaccess = providerxml.attribute("webaccess");
    //provider.setDownloadUrl(KUrl(downloadurl));
    provider.setUploadUrl(KUrl(uploadurl));
    provider.setNoUploadUrl(KUrl(nouploadurl));
    provider.setWebService(KUrl(webservice));
    provider.setWebAccess(KUrl(webaccess));

    QString downloadurl = providerxml.attribute("downloadurl");
    QString downloadlatest = providerxml.attribute("downloadurl-latest");
    QString downloadscore = providerxml.attribute("downloadurl-score");
    QString downloaddownloads = providerxml.attribute("downloadurl-downloads");

    if (!downloadlatest.isEmpty()) {
        Feed *feedlatest = new Feed();
        feedlatest->setName(i18nc("describes the feed of the latest posted entries", "Latest"));
        feedlatest->setFeedUrl(downloadlatest);
        provider.addDownloadUrlFeed("latest", feedlatest);
    }
    if (!downloadscore.isEmpty()) {
        Feed *feedscore = new Feed();
        feedscore->setName(i18n("Highest Rated"));
        feedscore->setFeedUrl(downloadscore);
        provider.addDownloadUrlFeed("score", feedscore);
    }
    if (!downloaddownloads.isEmpty()) {
        Feed *feeddownloads = new Feed();
        feeddownloads->setName(i18n("Most Downloads"));
        feeddownloads->setFeedUrl(downloaddownloads);
        provider.addDownloadUrlFeed("downloads", feeddownloads);
    }
    if (!downloadurl.isEmpty()) {
        Feed *feedgeneric = new Feed();
        // feedgeneric->setName(i18n("Unsorted"));
        // Currently this is used for latest
        feedgeneric->setName(i18nc("describes the feed of the latest posted entries", "Latest"));
        feedgeneric->setFeedUrl(downloadurl);
        provider.addDownloadUrlFeed(QString(), feedgeneric);
    }

    // FIXME: what exactly is the following condition supposed to do?
    // FIXME: make sure new KUrl in KDE 4 handles this right
    // FIXME: this depends on freedesktop.org icon naming... introduce 'desktopicon'?
    KUrl iconurl(providerxml.attribute("icon"));
    if (!iconurl.isValid()) iconurl.setPath(providerxml.attribute("icon"));
    provider.setIcon(iconurl);

    QDomNode n;
    for (n = providerxml.firstChild(); !n.isNull(); n = n.nextSibling()) {
        QDomElement e = n.toElement();
        if (e.tagName() == "title") {
            QString lang = e.attribute("lang");
            name.addString(lang, e.text().trimmed());
        }
    }

    provider.setName(name);

    // Validation

    if ((provider.noUploadUrl().isValid()) && (provider.uploadUrl().isValid())) {
        //kWarning(550) << "ProviderHandler: both uploadurl and nouploadurl given";
        return provider;
    }

    if ((!provider.noUploadUrl().isValid()) && (!provider.uploadUrl().isValid())) {
        if (!provider.webService().isValid()) {
            //kWarning(550) << "ProviderHandler: neither uploadurl nor nouploadurl nor DXS given";
            return provider;
        }
    }

    // Provider is valid

    mValid = true;
    return provider;
}
Exemple #6
0
Feed * Feed::create(const FeedData &feedData, QObject *parent)
{
    Feed * returned = new Feed(parent);
    returned->d_func()->data = feedData;
    return returned;
}
Exemple #7
0
LRESULT TorrentDialog::OnNotify(int idCtrl, LPNMHDR pnmh) {
  Feed* feed = Aggregator.Get(FEED_CATEGORY_LINK);
  if (!feed) return 0;

  // ListView control
  if (idCtrl == IDC_LIST_TORRENT) {
    switch (pnmh->code) {
      // Column click
      case LVN_COLUMNCLICK: {
        LPNMLISTVIEW lplv = (LPNMLISTVIEW)pnmh;
        int order = 1;
        if (lplv->iSubItem == list_.GetSortColumn()) order = list_.GetSortOrder() * -1;
        switch (lplv->iSubItem) {
          // Episode
          case 1:
            list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_NUMBER, ListViewCompareProc);
            break;
          // File size
          case 3:
            list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_FILESIZE, ListViewCompareProc);
            break;
          // Other columns
          default:
            list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_DEFAULT, ListViewCompareProc);
            break;
        }
        break;
      }

      // Check/uncheck
      case LVN_ITEMCHANGED: {
        if (!list_.IsVisible()) break;
        LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(pnmh);
        if (pnmv->uOldState != 0 && (pnmv->uNewState == 0x1000 || pnmv->uNewState == 0x2000)) {
          int checked_count = 0;
          for (int i = 0; i < list_.GetItemCount(); i++) {
            if (list_.GetCheckState(i)) checked_count++;
          }
          if (checked_count == 1) {
            MainDialog.ChangeStatus(L"Marked 1 torrent.");
          } else {
            MainDialog.ChangeStatus(L"Marked " + ToWstr(checked_count) + L" torrents.");
          }
          FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(pnmv->iItem));
          if (feed_item) {
            bool checked = list_.GetCheckState(pnmv->iItem) == TRUE;
            feed_item->state = checked ? FEEDITEM_SELECTED : FEEDITEM_DISCARDED_NORMAL;
          }
        }
        break;
      }

      // Double click
      case NM_DBLCLK: {
        if (list_.GetSelectedCount() > 0) {
          LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh);
          if (lpnmitem->iItem == -1) break;
          FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem));
          if (feed_item) {
            feed->Download(feed_item->index);
          }
        }
        break;
      }

      // Right click
      case NM_RCLICK: {
        LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh);
        if (lpnmitem->iItem == -1) break;
        FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem));
        if (feed_item) {
          wstring answer = UI.Menus.Show(m_hWindow, 0, 0, L"TorrentListRightClick");
          if (answer == L"DownloadTorrent") {
            feed->Download(feed_item->index);
          } else if (answer == L"Info") {
            auto anime_id = feed_item->episode_data.anime_id;
            if (anime_id) {
              ExecuteAction(L"Info", 0, anime_id);
            } else {
              ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")");
            }
          } else if (answer == L"DiscardTorrent") {
            feed_item->state = FEEDITEM_DISCARDED_NORMAL;
            list_.SetCheckState(lpnmitem->iItem, FALSE);
            Aggregator.file_archive.push_back(feed_item->title);
          } else if (answer == L"DiscardTorrents") {
            auto anime_item = AnimeDatabase.FindItem(feed_item->episode_data.anime_id);
            if (anime_item) {
              for (int i = 0; i < list_.GetItemCount(); i++) {
                feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i));
                if (feed_item && feed_item->episode_data.anime_id == anime_item->GetId()) {
                  feed_item->state = FEEDITEM_DISCARDED_NORMAL;
                  list_.SetCheckState(i, FALSE);
                }
              }
              Aggregator.filter_manager.AddFilter(
                FEED_FILTER_ACTION_DISCARD, FEED_FILTER_MATCH_ALL, FEED_FILTER_OPTION_DEFAULT,
                true, L"Discard \"" + anime_item->GetTitle() + L"\"");
              Aggregator.filter_manager.filters.back().AddCondition(
                FEED_FILTER_ELEMENT_META_ID, FEED_FILTER_OPERATOR_EQUALS, 
                ToWstr(anime_item->GetId()));
            }
          } else if (answer == L"SelectFansub") {
            int anime_id = feed_item->episode_data.anime_id;
            wstring group_name = feed_item->episode_data.group;
            if (anime_id > anime::ID_UNKNOWN && !group_name.empty()) {
              for (int i = 0; i < list_.GetItemCount(); i++) {
                feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i));
                if (feed_item && !IsEqual(feed_item->episode_data.group, group_name)) {
                  feed_item->state = FEEDITEM_DISCARDED_NORMAL;
                  list_.SetCheckState(i, FALSE);
                }
              }
              anime::SetFansubFilter(anime_id, group_name);
            }
          } else if (answer == L"MoreTorrents") {
            Search(Settings.RSS.Torrent.search_url, feed_item->episode_data.title);
          } else if (answer == L"SearchMAL") {
            ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")");
          }
        }
        break;
      }

      // Custom draw
      case NM_CUSTOMDRAW: {
        LPNMLVCUSTOMDRAW pCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pnmh);
        switch (pCD->nmcd.dwDrawStage) {
          case CDDS_PREPAINT:
            return CDRF_NOTIFYITEMDRAW;
          case CDDS_ITEMPREPAINT:
            return CDRF_NOTIFYSUBITEMDRAW;
          case CDDS_PREERASE:
          case CDDS_ITEMPREERASE:
            return CDRF_NOTIFYPOSTERASE;

          case CDDS_ITEMPREPAINT | CDDS_SUBITEM: {
            // Alternate background color
            if ((pCD->nmcd.dwItemSpec % 2) && !list_.IsGroupViewEnabled())
              pCD->clrTextBk = ChangeColorBrightness(GetSysColor(COLOR_WINDOW), -0.03f);
            FeedItem* feed_item = reinterpret_cast<FeedItem*>(pCD->nmcd.lItemlParam);
            if (feed_item) {
#ifdef _DEBUG
              // Change background color
              switch (feed_item->state) {
                case FEEDITEM_DISCARDED_NORMAL:
                case FEEDITEM_DISCARDED_INACTIVE:
                case FEEDITEM_DISCARDED_HIDDEN:
                  pCD->clrTextBk = theme::COLOR_LIGHTRED;
                  break;
                case FEEDITEM_SELECTED:
                  pCD->clrTextBk = theme::COLOR_LIGHTGREEN;
                  break;
                default:
                  pCD->clrTextBk = GetSysColor(COLOR_WINDOW);
                  break;
              }
#endif
              // Change text color
              if (feed_item->state == FEEDITEM_DISCARDED_INACTIVE) {
                pCD->clrText = GetSysColor(COLOR_GRAYTEXT);
              } else if (feed_item->episode_data.new_episode) {
                pCD->clrText = GetSysColor(pCD->iSubItem == 1 ? COLOR_HIGHLIGHT : COLOR_WINDOWTEXT);
              }
            }
            return CDRF_NOTIFYPOSTPAINT;
          }
        }
      }
    }
  }

  return 0;
}
void FeedListener::MessageReceived(BMessage *msg) {
	switch (msg->what) {
		case B_SOME_APP_LAUNCHED: {
			const char *signature = NULL;
			if (msg->FindString("be:signature", &signature) != B_OK) return;
			
			if (strcmp(signature, FeedKit::ServerSignature) == 0) {
				fMsgr = BMessenger(FeedKit::ServerSignature);
				
				if ((fListening == true) && (fRegistered == false)) {
					AddListener(fTarget);
				};
								
				for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
					(*hIt)->ServerStarted();
				}
			};
		} break;
		
		case B_SOME_APP_QUIT: {
			const char *signature = NULL;
			if (msg->FindString("be:signature", &signature) != B_OK) return;
			
			if ((fRegistered == true) && (strcmp(signature, FeedKit::ServerSignature) == 0)) {
				fRegistered = false;
				
				for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
					(*hIt)->ServerShutdown();
				};
			};
		} break;
		
		case FeedKit::Private::FromServer::RegisterFeedComplete: {
			Feed feed;
			if (msg->FindFlat("feed", &feed) == B_OK) {
				for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
					(*hIt)->FeedRegistered(&feed);
				};
			};
		} break;
		
		case FeedKit::Private::FromServer::ChannelUpdated: {
			Feed feed;
			const char *channelUUID;
			Channel *channel;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			
			channel = feed.ChannelByUUID(channelUUID);
						
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->ChannelUpdated(&feed, channel);
			};
		} break;

		case FeedKit::Private::FromServer::ItemRead: {
			Feed feed;
			const char *channelUUID;
			const char *itemUUID;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindString("item", &itemUUID) != B_OK) return;
			
			Channel *channel = feed.ChannelByUUID(channelUUID);
			Item *item = channel->ItemByUUID(itemUUID);
			
			channel->ParentFeed(&feed);
			item->ParentChannel(channel);
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->ItemRead(&feed, channel, item);
			};
		} break;
		
		case FeedKit::Private::FromServer::RegisterFeedError: {
			Feed feed;
			ErrorDetails error;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindFlat("error", &error) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedRegisteredError(&feed, &error);
			};
		} break;
		
		case FeedKit::Private::FromServer::DownloadFeedStarted: {
			Feed feed;
			DownloadProgress progress;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindFlat("download", &progress) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedDownloadStarted(&feed, &progress);
			};		
		} break;
		
		case FeedKit::Private::FromServer::DownloadFeedError: {
			Feed feed;
			DownloadProgress progress;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindFlat("download", &progress) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedDownloadError(&feed, &progress);
			};		
		} break;

		case FeedKit::Private::FromServer::DownloadFeedProgress: {
			Feed feed;
			DownloadProgress progress;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindFlat("download", &progress) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedDownloadProgress(&feed, &progress);
			};
		} break;

		case FeedKit::Private::FromServer::DownloadFeedFinished: {
			Feed feed;
			DownloadProgress progress;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindFlat("download", &progress) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedDownloadFinished(&feed, &progress);
			};
		} break;

		case FeedKit::Private::FromServer::DownloadEnclosureStarted: {
			Feed feed;
			const char *channelUUID = NULL;
			const char *itemUUID = NULL;
			const char *enclosureUUID = NULL;
					
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindString("item", &itemUUID) != B_OK) return;
			if (msg->FindString("enclosure", &enclosureUUID) != B_OK) return;
			
			Channel *channel = feed.ChannelByUUID(channelUUID);
			Item *item = channel->ItemByUUID(itemUUID);
			Enclosure *enclosure = item->EnclosureByUUID(enclosureUUID);
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->EnclosureDownloadStarted(&feed, item, enclosure);
			};
		} break;
		
		case FeedKit::Private::FromServer::DownloadEnclosureProgress: {
			Feed feed;
			const char *channelUUID = NULL;
			const char *itemUUID = NULL;
			const char *enclosureUUID = NULL;

			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindString("item", &itemUUID) != B_OK) return;
			if (msg->FindString("enclosure", &enclosureUUID) != B_OK) return;

			Channel *channel = feed.ChannelByUUID(channelUUID);
			Item *item = channel->ItemByUUID(itemUUID);
			Enclosure *enclosure = item->EnclosureByUUID(enclosureUUID);

			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->EnclosureDownloadProgress(&feed, item, enclosure);
			};
		} break;
		
		case FeedKit::Private::FromServer::DownloadEnclosureFinished: {	
			Feed feed;
			const char *channelUUID = NULL;
			const char *itemUUID = NULL;
			const char *enclosureUUID = NULL;

			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindString("item", &itemUUID) != B_OK) return;
			if (msg->FindString("enclosure", &enclosureUUID) != B_OK) return;
			
			Channel *channel = feed.ChannelByUUID(channelUUID);
			Item *item = channel->ItemByUUID(itemUUID);
			Enclosure *enclosure = item->EnclosureByUUID(enclosureUUID);
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->EnclosureDownloadFinished(&feed, item, enclosure);
			};
		} break;
		
		case FeedKit::Private::FromServer::EnclosureDownloadStatusChanged: {
			Feed feed;
			const char *channelUUID = NULL;
			const char *itemUUID = NULL;
			const char *enclosureUUID = NULL;

			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindString("item", &itemUUID) != B_OK) return;
			if (msg->FindString("enclosure", &enclosureUUID) != B_OK) return;
			
			Channel *channel = feed.ChannelByUUID(channelUUID);
			Item *item = channel->ItemByUUID(itemUUID);
			Enclosure *enclosure = item->EnclosureByUUID(enclosureUUID);
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->EnclosureDownloadStatusChanged(&feed, item, enclosure);
			};
		} break;
		
		case FeedKit::Private::FromServer::ChannelIconUpdated: {
			Feed feed;
			const char *channelUUID = NULL;
			Channel *channel = NULL;
			entry_ref ref;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			if (msg->FindString("channel", &channelUUID) != B_OK) return;
			if (msg->FindRef("ref", &ref) != B_OK) return;

			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->ChannelIconUpdated(&feed, channel, ref);
			};
		} break;
		
		case FeedKit::Private::FromServer::FeedSubscriptionChanged: {
			Feed feed;
			
			if (msg->FindFlat("feed", &feed) != B_OK) return;
			
			for (handler_t::iterator hIt = fHandler.begin(); hIt != fHandler.end(); hIt++) {
				(*hIt)->FeedSubscriptionChanged(&feed);
			};
		} break;
		
		default: {
			BLooper::MessageReceived(msg);
		};
	};
};
Exemple #9
0
void Dxs::slotResult(QDomNode node, int jobid)
{
    //kDebug() << "LOCALNAME: " << m_soap->localname(node);

    bool success = true;
    if (m_soap->localname(node) == "Fault") {
        success = false;
        emit signalFault();
        return;
    }

    if (m_soap->localname(node) == "GHNSInfoResponse") {
        QString provider = m_soap->xpath(node, "/provider");
        QString server = m_soap->xpath(node, "/server");
        QString version = m_soap->xpath(node, "/version");

        emit signalInfo(provider, server, version);
    } else if (m_soap->localname(node) == "GHNSCategoriesResponse") {
        QList<KNS::Category*> categories;

        QList<QDomNode> catlist = m_soap->directChildNodes(node, "category");
        for (int i = 0; i < catlist.count(); i++) {
            KNS::Category *category = new KNS::Category();

            QDomNode node = catlist.at(i).toElement();
            QString categoryname = m_soap->xpath(node, "/category");
            QString icon = m_soap->xpath(node, "/icon");
            QString name = m_soap->xpath(node, "/name");
            QString description = m_soap->xpath(node, "/description");

            category->setId(categoryname);
            category->setName(name);
            category->setIcon(icon);
            category->setDescription(description);

            categories << category;
        }

        emit signalCategories(categories);
    } else if (m_soap->localname(node) == "GHNSListResponse") {
        QList<KNS::Entry*> entries;

        Feed * thisFeed = m_jobfeeds.value(jobid);
        QDomNode entriesNode = node.firstChild();
        // FIXME: find a way to put a real assertion in here to ensure the entriesNode is the "entries" node
        //Q_ASSERT(entriesNode.localName() == "entries");

        QList<QDomNode> entrylist = m_soap->directChildNodes(entriesNode, "entry");
        for (int i = 0; i < entrylist.count(); i++) {
            QDomElement element = entrylist.at(i).toElement();
            element.setTagName("stuff");
            KNS::EntryHandler handler(element);
            KNS::Entry *entry = handler.entryptr();

            entries << entry;
            thisFeed->addEntry(entry);
            //kDebug() << "ENTRY: " << entry->name().representation() << " location: " << entry->payload().representation();
        }

        emit signalEntries(entries, thisFeed);
    } else if (m_soap->localname(node) == "GHNSCommentsResponse") {
        QStringList comments;

        QList<QDomNode> comlist = m_soap->directChildNodes(node, "comments");
        for (int i = 0; i < comlist.count(); i++) {
            comments << comlist.at(i).toElement().text();
        }

        emit signalComments(comments);
    } else if (m_soap->localname(node) == "GHNSChangesResponse") {
        QStringList changes;

        QList<QDomNode> changelist = m_soap->directChildNodes(node, "entry");
        for (int i = 0; i < changelist.count(); i++) {
            QDomNode node = changelist.at(i);

            QString version = m_soap->xpath(node, "/version");
            QString changelog = m_soap->xpath(node, "/changelog");
            //kDebug() << "CHANGELOG: " << version << " " << changelog;

            changes << changelog;
        }

        // FIXME: pass (version, changelog) pairs - Python I miss you :-)
        emit signalChanges(changes);
    } else if (m_soap->localname(node) == "GHNSHistoryResponse") {
        QStringList entries;

        QList<QDomNode> entrylist = m_soap->directChildNodes(node, "entry");
        for (int i = 0; i < entrylist.count(); i++) {
            entries << entrylist.at(i).toElement().text();
        }

        emit signalHistory(entries);
    } else if (m_soap->localname(node) == "GHNSRemovalResponse") {
        emit signalRemoval(success);
    } else if (m_soap->localname(node) == "GHNSSubscriptionResponse") {
        emit signalSubscription(success);
    } else if (m_soap->localname(node) == "GHNSCommentResponse") {
        emit signalComment(success);
    } else if (m_soap->localname(node) == "GHNSRatingResponse") {
        emit signalRating(success);
    }
}