[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/pim/kblogger/src
From: Antonio Aloisio <antonio.aloisio () gmail ! com>
Date: 2008-02-21 14:41:29
Message-ID: 1203604889.877414.10661.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 777765 by aloisio:
Fix partially thumbnail/media import, now it works with a simple regexp, but we need \
to get the regexp from blogList. ImportMediaWidget need more work. Clean \
profileConfigDialogBase UI.
M +9 -2 media/importmediadialog.h
M +54 -29 media/importmediawidget.cpp
M +15 -4 media/importmediawidget.h
M +2 -2 media/medialist.cpp
M +0 -1 profiles/profileconfigdialog.cpp
M +3 -28 profiles/profileconfigdialogbase.ui
--- trunk/playground/pim/kblogger/src/media/importmediadialog.h #777764:777765
@@ -33,10 +33,17 @@
class ImportMediaWidget;
/**
- * This class manages the Dialog Import local and remote media in kblogger inside
- * a singleton.
+ * FIXME is Singleton really necessary? Can we use another way to have only 1 \
instance of this class? + * TODO This class shouldn't be a child of KDialog.
*/
+/**
+ * @brief
+ * Only one instance of this class will run at once, so this class is singleton.
+ * Other classes use addUrl to insert the media to download in the importMediaWidget \
Donwload List. + * The Download job start to run when the user click OK Button.
+ */
+
class ImportMediaDialog : public KDialog
{
Q_OBJECT
--- trunk/playground/pim/kblogger/src/media/importmediawidget.cpp #777764:777765
@@ -49,13 +49,13 @@
{
kDebug();
// clean things up
- QList<QTreeWidgetItem*>::ConstIterator it = urls.begin();
- QList<QTreeWidgetItem*>::ConstIterator end = urls.end();
+ QList<QTreeWidgetItem*>::ConstIterator it = treeItemList.begin();
+ QList<QTreeWidgetItem*>::ConstIterator end = treeItemList.end();
for( ; it != end; it++ ){
mediaTreeWidget->removeItemWidget( *it, 0 );
delete( *it );
}
- urls.clear();
+ treeItemList.clear();
}
bool ImportMediaWidget::addUrl(const QString& url, const QString& blogname, const \
QString& postId) @@ -73,27 +73,29 @@
return false;
}
- //Blogger.com thumbnails look like this:
- // http://xxx.blogger.com/_lJiR72o3Bww/R1MvGt1yWmI/AAAAAAAAAT4/sXtF1aY1HQY/s320/IMG_9261.JPG
- // TODO check for www.blogspot.com urls
-// QRegExp bloggerThumbnailRx("http://[\\d\\w]*.blogger.com/([\\d\\w]*/){1,4}s320/IMG_\\d*.JPG");
+ QRegExp thumbnailUrlRx("thumb");/*TODO Get thumbnailUrlRx from BlogList*/
QTreeWidgetItem *item;
- // FIXME this does not work reliably look at the note in handleJobResult
-// if ( !urls.isEmpty() && ( url.contains("thumb") || //Generic
-// url.contains(bloggerThumbnailRx ) )
-// ) { //NOTE Improve it!
-// item = new QTreeWidgetItem( urls.last() ); //Thumbnail
-// } else
-
- item = new QTreeWidgetItem( mediaTreeWidget ); //No Thumbnail
+ /*NOTE usually the code that contains a thumbnail looks like this:
+ * <a href="myimage.jpg" >
+ * <img src="myimage.thumb.jpg"> <--thumbnailUrlRx will match the string \
between the '"'. + *</a>
+ * So kblogger will process the thumbnail before the image.
+ */
+ //FIXME does this only simple condition work reliably?
+ if ( url.contains( thumbnailUrlRx ) ) {
+ item = new QTreeWidgetItem( treeItemList.last() ); //Thumbnail
+ }else{
+ item = new QTreeWidgetItem( mediaTreeWidget ); //No Thumbnail
+ }
+
item->setText(0, url );
item->setIcon(0, KIcon("document-import") );
item->setText(1, blogname );
item->setText(2, postId );
item->setText(3, i18n("Not downloaded yet"));
mediaTreeWidget->insertTopLevelItem( 0, item );
- urls += item;
+ treeItemList += item;
return true;
}
@@ -101,8 +103,8 @@
{
kDebug();
//Download the urls in the media cache
- QList<QTreeWidgetItem*>::ConstIterator it = urls.begin();
- QList<QTreeWidgetItem*>::ConstIterator end = urls.end();
+ QList<QTreeWidgetItem*>::ConstIterator it = treeItemList.begin();
+ QList<QTreeWidgetItem*>::ConstIterator end = treeItemList.end();
for( ; it != end; it++ ){
createMediaFromUrl( *it );
}
@@ -198,18 +200,9 @@
item->setIcon(0, KIcon("dialog-ok-apply") );
item->setText(3, QString("%1 Kb").arg(mediaData.count() / 1024));
- //Thumbnail managing FIXME this does not work, since the jobs may not
- // call this function in the correct order
-// if ( prev_media && filename.contains("thumb") ) {
-// prev_media->setThumbnail(media);
-// media->setFullSizeImage(prev_media);
-// prev_media = 0; // this is a thumbnail
-// } else {
-// prev_media = media;
-// }
+ //Thumbnail managing
+ mediaMap[item]=media;
- //Add Media in the MediaListWidget
- ItemsManager::self()->addMedia(media);
} else {
item->setIcon(0, KIcon("dialog-cancel") );
item->setText(3, i18n("CacheFile writing Error"));
@@ -219,13 +212,45 @@
void ImportMediaWidget::closeParent()
{
+ kDebug();
if( jobsMap.isEmpty() ) {
kDebug() << "all jobs finished: closing the parent dialog.";
+ processCreatedMedia();
Q_ASSERT( mParent );
mParent->close();
}
}
+void ImportMediaWidget::processCreatedMedia(){
+ kDebug();
+
+ for (int i = 0; i < treeItemList.size(); ++i) {
+// for (int i = treeItemList.size()-1; i >0; --i ) {
+ QTreeWidgetItem* currentItem=treeItemList[i];
+ Q_ASSERT(currentItem);
+
+ QTreeWidgetItem* parentItem=currentItem->parent();
+ Media* currentMedia=mediaMap[ currentItem ];
+ if (!currentMedia){
+ //Media is null when a job exits with error.
+ kDebug() << "currentMedia is null. Continue..";
+ continue;
+ }
+ Media* previouslyMedia=0;
+
+ if ( i > 0 ){
+ previouslyMedia=mediaMap[ treeItemList[i-1] ];
+ }
+ //If currentItem has a parent (a QTreeWidgetItem),it's a thumbnail
+ if ( parentItem && previouslyMedia ){
+ currentMedia->setFullSizeImage( previouslyMedia );
+ previouslyMedia->setThumbnail( currentMedia );
+ }
+ //
+ ItemsManager::self()->addMedia( currentMedia );
+ }
+}
+
} //Namespace
#include "importmediawidget.moc"
--- trunk/playground/pim/kblogger/src/media/importmediawidget.h #777764:777765
@@ -31,6 +31,8 @@
/**
* This Dialog Import local and remote media in kblogger
+ * Some urls cannot be imported (Eg: too big! ), so they are blacklisted.
+ * KBlogger save blacklisted urls in a file.
*/
class ImportMediaWidget : public QWidget, public Ui::ImportMediaWidgetBase
@@ -54,12 +56,21 @@
private:
// created for convenience in handleFileJobResult()
void closeParent();
-
+ //
+ void createMediaFromUrl(QTreeWidgetItem*);
+ /* 1) Scan mediaMap to find QTreeWidgetItem with a parent (thumbnail QTWI)
+ * and set parent and child media to FullSizeImage and Thumbnail
+ * 2) Add all created Media in the MediaListWidget, so they are user visible.
+ */
+ void processCreatedMedia();
+
+
+ //Vars
KDialog *mParent;
- void createMediaFromUrl(QTreeWidgetItem*);
- QList<QTreeWidgetItem*> urls;
+ QList<QTreeWidgetItem*> treeItemList;
QMap<KJob*,QTreeWidgetItem*> jobsMap;
- //Number of the urls skipped because they are blacklisted
+ QMap<QTreeWidgetItem*,Media*> mediaMap;
+ //N ° of blacklisted urls.
int blackListedUrls;
};
--- trunk/playground/pim/kblogger/src/media/medialist.cpp #777764:777765
@@ -119,7 +119,7 @@
if ( fullSizeMedia ) {
kbMediaItem = new QTreeWidgetItem( mMediaMap.key(fullSizeMedia) );
} else {
- kbMediaItem = new QTreeWidgetItem(listTree);
+ kbMediaItem = new QTreeWidgetItem( listTree );
}
kbMediaItem->setIcon (Name, kbMedia->icon() );
@@ -192,7 +192,7 @@
void MediaList::appendMedia(Media* kbMedia)
{
- kDebug();
+ kDebug() << "Media name:" << kbMedia->name();
if ( kbMedia->checksum() == 0 ) return;
MediaListWidget::appendMedia( kbMedia );
--- trunk/playground/pim/kblogger/src/profiles/profileconfigdialog.cpp #777764:777765
@@ -53,7 +53,6 @@
// initialize the combo box for the blog types
// new code to use the BlogList
// NOTE: this means reording the BlogList int index breaks old configurations!
- kcfg_Type->clear();
mBlogList = BlogList();
for( int i=0; i < mBlogList.count(); i++ ){
// check the url against the url regexp
--- trunk/playground/pim/kblogger/src/profiles/profileconfigdialogbase.ui \
#777764:777765 @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>465</width>
- <height>273</height>
+ <width>485</width>
+ <height>282</height>
</rect>
</property>
<property name="sizePolicy" >
@@ -190,7 +190,7 @@
</size>
</property>
<property name="text" >
- <string>API:</string>
+ <string>Blog system:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
@@ -205,31 +205,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <item>
- <property name="text" >
- <string>Blogger API 1.0</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>MetaWeblog API</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>MovableType API</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>MT for Wordpress API</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>GData API</string>
- </property>
- </item>
</widget>
</item>
<item>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic