nomnom_de.ts: Add missing translations
[nomnom.git] / src / Video.cpp
blob0285915b120cd171fdf5c9fa49c0c102ac8e5174
1 /*
2 * Copyright (C) 2010 Toni Gundogdu.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <QString>
19 #include <QVariant>
20 #include <QLabel>
21 #include <QScriptEngine>
22 #include <QScriptValueIterator>
23 #include <QDebug>
25 #include "Video.h"
27 // Ctor.
29 Video::Video ()
30 : QObject(), _length (0)
31 { }
33 Video::Video (const Video& v)
34 : QObject(), _length(0)
36 _link = v._link;
37 _title = v._title;
38 _pageURL = v._pageURL;
39 _id = v._id;
40 _format = v._format;
41 _length = v._length;
42 _suffix = v._suffix;
43 _ctype = v._ctype;
46 Video&
47 Video::operator=(const Video&)
49 return *this;
52 // Parse from JSON.
54 bool
55 Video::fromJSON (const QString& data, QString& error)
57 QScriptEngine e;
59 QScriptValue v = e.evaluate ("(" +data+ ")");
61 if (e.hasUncaughtException ())
63 error = tr ("Uncaught exception at line %1: %2")
64 .arg (e.uncaughtExceptionLineNumber ())
65 .arg (v.toString ());
66 return false;
69 _title = v.property ("page_title").toString ().simplified ();
70 _pageURL = v.property ("page_url").toString ();
71 _id = v.property ("id").toString ();
72 _host = v.property ("host").toString ();
74 QScriptValueIterator i (v.property ("link"));
76 if ( !i.hasNext () )
78 error = tr("Expected at least one video link from quvi(1), got none.");
79 return false;
82 i.next ();
83 v = i.value ();
85 _length = v.property ("length_bytes").toVariant ().toLongLong ();
86 _ctype = v.property ("content_type").toString ();
87 _suffix = v.property ("file_suffix").toString ();
88 _link = v.property ("url").toString ();
90 #ifdef _0
91 qDebug ()
92 << _length
93 << _ctype
94 << _suffix
95 << _link;
96 #endif
98 return true;
101 // Get.
103 QVariant
104 Video::get (Detail d) const
106 switch (d)
108 case Link :
109 return QVariant (_link);
110 case Title :
111 return QVariant (_title);
112 case PageURL :
113 return QVariant (_pageURL);
114 case ID :
115 return QVariant (_id);
116 case Format :
117 return QVariant (_format);
118 case Length :
119 return QVariant (_length);
120 case Suffix :
121 return QVariant (_suffix);
122 case ContentType:
123 return QVariant (_ctype);
124 case Host :
125 return QVariant(_host);
128 return QVariant();
131 // Set.
133 void
134 Video::set (Detail d, const QString& s)
136 bool ignored = false;
137 switch (d)
139 case Link :
140 _link = s;
141 break;
142 case Title :
143 _title = s;
144 break;
145 case PageURL :
146 _pageURL = s;
147 break;
148 case ID :
149 _id = s;
150 break;
151 case Format :
152 _format = s;
153 break;
154 case Length :
155 _length = s.toLongLong(&ignored);
156 break;
157 case Suffix :
158 _suffix = s;
159 break;
160 case ContentType:
161 _ctype = s;
162 break;
163 case Host :
164 _host = s;
165 break;
166 default :
167 break;
171 // VideoException: ctor.
173 VideoException::VideoException (const QString& errmsg)
174 : errmsg(errmsg)
177 // VideoException: what.
179 const QString&
180 VideoException::what() const
182 return errmsg;
185 // vim: set ts=2 sw=2 tw=72 expandtab: