2
* =====================================================================================
4
* Filename: recentchannel.cpp
9
* Created: 2007年12月02日 20时19分58秒 CST
13
* Author: lerosua (), lerosua@gmail.com
16
* =====================================================================================
23
#include "recentchannel.h"
24
#include "MainWindow.h"
25
#include "mmsLivePlayer.h"
26
#include "sopcastLivePlayer.h"
27
#include "pplivePlayer.h"
28
#include "ppsPlayer.h"
30
RecentChannel::RecentChannel(MainWindow* parent_):Channel( parent_)
35
RecentChannel::~RecentChannel()
38
LivePlayer* RecentChannel::get_player( const std::string& stream,TypeChannel page)
42
return MmsLivePlayer::create(stream);
44
return PpLivePlayer::create(stream);
46
return SopcastLivePlayer::create(stream);
48
return PPSPlayer::create(stream);
54
void RecentChannel::init()
57
std::string homedir=Glib::get_user_config_dir();
58
snprintf(buf, 512,"%s/gmlive/recent.lst",homedir.c_str());
59
std::ifstream file(buf);
61
std::ofstream out(buf);
64
//std::cout<<"file error\n";
72
std::string trimstring = "\t";
74
while(std::getline(file,line)){
75
size_t pos = line.find_first_of("#");
76
if(pos==std::string::npos)
78
name = line.substr(0,pos);
79
last = line.substr(pos+1,std::string::npos);
81
pos = last.find_first_of("#");
82
if(pos==std::string::npos)
84
//stream=last.substr(0,pos);
85
stream=last.substr(0,last.find_first_of(trimstring));
86
type= last.substr(pos+1,std::string::npos);
89
addLine(id,name,stream,type);
97
void RecentChannel::addLine(int num,const Glib::ustring& name,const std::string& stream_,const Glib::ustring& type)
102
else if("pplive" == type)
104
if(!parent->support_pplive())
107
type_ = PPLIVE_CHANNEL;
109
else if("sopcast" == type)
111
if(!parent->support_sopcast())
114
type_ = SOPCAST_CHANNEL;
116
else if("ppstream" == type)
124
Gtk::TreeModel::iterator iter = m_liststore->prepend();
125
(*iter)[columns.name] = name;
126
(*iter)[columns.freq] = 100;
127
(*iter)[columns.stream]=stream_;
130
(*iter)[columns.type]=type_ ;
134
void RecentChannel::saveLine(const Glib::ustring & name,const std::string& stream_,TypeChannel type)
138
std::string homedir=Glib::get_user_config_dir();
139
snprintf(buf, 512,"%s/gmlive/recent.lst",homedir.c_str());
140
std::ifstream file(buf);
141
std::vector<std::string> list;
143
printf("buf is %s\n",buf);
144
std::cout<<"file error\n";
150
while(std::getline(file,line)){
151
list.push_back(line);
161
if(type == MMS_CHANNEL)
163
//stream = name +"\t#"+stream_+"\t#mms";
166
else if (type == SOPCAST_CHANNEL)
168
//stream = name +"\t#"+stream_+"\t#sopcast";
171
else if(type == PPLIVE_CHANNEL)
173
//stream = name +"\t#"+stream_+"\t#pplive";
176
else if(type ==PPS_CHANNEL)
178
//stream = name +"\t#"+stream_+"\t#ppstream";
179
strtype = "ppstream";
182
stream = name +"\t#"+stream_+"\t#"+strtype;
183
std::vector<std::string>::iterator iter = std::find(list.begin(),list.end(),stream);
184
if(iter == list.end())
186
list.push_back(stream);
187
std::ofstream outfile(buf);
188
for(iter=list.begin();iter!=list.end();++iter)
190
if(iter == list.begin()&&(num==10))
193
outfile<<*iter<<std::endl;
198
addLine(users, name,stream_,strtype);