File indexing completed on 2024-05-05 03:50:48
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de> 0004 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com> 0005 // 0006 0007 0008 // Self 0009 #include "PhotoPluginItem.h" 0010 0011 // Plugin 0012 #include "CoordinatesParser.h" 0013 #include "PhotoPluginModel.h" 0014 0015 // Marble 0016 #include "GeoDataCoordinates.h" 0017 #include "GeoPainter.h" 0018 #include "MarbleGraphicsGridLayout.h" 0019 #include "TinyWebBrowser.h" 0020 #include "ViewportParams.h" 0021 #include "MarbleDebug.h" 0022 #include "MarbleWidget.h" 0023 #include "MarbleModel.h" 0024 #include "RenderPlugin.h" 0025 #include "PluginManager.h" 0026 #include "layers/PopupLayer.h" 0027 0028 // Qt 0029 #include <QAction> 0030 #include <QIcon> 0031 #include <QFile> 0032 #include <QHash> 0033 #include <QUrl> 0034 #include <QPixmap> 0035 0036 using namespace Marble; 0037 0038 PhotoPluginItem::PhotoPluginItem( MarbleWidget *widget, QObject *parent ) 0039 : AbstractDataPluginItem( parent ), 0040 m_marbleWidget( widget ), 0041 m_image( this ), 0042 m_browser( nullptr ) 0043 { 0044 m_action = new QAction( this ); 0045 connect( m_action, SIGNAL(triggered()), this, SLOT(openBrowser()) ); 0046 setCacheMode( ItemCoordinateCache ); 0047 0048 m_image.setFrame( FrameGraphicsItem::ShadowFrame ); 0049 m_image.setBorderBrush( QBrush( QColor( Qt::white ) ) ); 0050 m_image.setBorderWidth( 2.0 ); 0051 m_image.setMargin( 5 ); 0052 MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 ); 0053 layout->addItem( &m_image, 0, 0 ); 0054 setLayout( layout ); 0055 } 0056 0057 PhotoPluginItem::~PhotoPluginItem() 0058 { 0059 delete m_browser; 0060 } 0061 0062 QString PhotoPluginItem::name() const 0063 { 0064 return title(); 0065 } 0066 0067 bool PhotoPluginItem::initialized() const 0068 { 0069 return !m_smallImage.isNull() && coordinate().isValid(); 0070 } 0071 0072 void PhotoPluginItem::addDownloadedFile( const QString& url, const QString& type ) 0073 { 0074 if (type == QLatin1String("thumbnail")) { 0075 m_smallImage.load( url ); 0076 m_image.setImage( m_smallImage.scaled( QSize( 50, 50 ) ) ); 0077 } 0078 else if (type == QLatin1String("info")) { 0079 QFile file( url ); 0080 if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) { 0081 return; 0082 } 0083 0084 GeoDataCoordinates coordinates; 0085 CoordinatesParser parser( &coordinates ); 0086 0087 if( parser.read( &file ) ) { 0088 setCoordinate( coordinates ); 0089 } 0090 } 0091 0092 if ( initialized() ) { 0093 emit updated(); 0094 } 0095 } 0096 0097 bool PhotoPluginItem::operator<( const AbstractDataPluginItem *other ) const 0098 { 0099 return this->id() < other->id(); 0100 } 0101 0102 QUrl PhotoPluginItem::photoUrl() const 0103 { 0104 QString url = "https://farm%1.static.flickr.com/%2/%3_%4_s.jpg"; 0105 0106 return QUrl( url.arg( farm() ).arg( server() ).arg( id() ).arg( secret() ) ); 0107 } 0108 0109 QUrl PhotoPluginItem::infoUrl() const 0110 { 0111 QHash<QString,QString> options; 0112 0113 options.insert( "photo_id", id() ); 0114 0115 return PhotoPluginModel::generateUrl( "flickr", "flickr.photos.geo.getLocation", options ); 0116 } 0117 0118 QString PhotoPluginItem::server() const 0119 { 0120 return m_server; 0121 } 0122 0123 void PhotoPluginItem::setServer( const QString& server ) 0124 { 0125 m_server = server; 0126 } 0127 0128 QString PhotoPluginItem::farm() const 0129 { 0130 return m_farm; 0131 } 0132 0133 void PhotoPluginItem::setFarm( const QString& farm ) 0134 { 0135 m_farm = farm; 0136 } 0137 0138 QString PhotoPluginItem::secret() const 0139 { 0140 return m_secret; 0141 } 0142 0143 void PhotoPluginItem::setSecret( const QString& secret ) 0144 { 0145 m_secret = secret; 0146 } 0147 0148 QString PhotoPluginItem::owner() const 0149 { 0150 return m_owner; 0151 } 0152 0153 void PhotoPluginItem::setOwner( const QString& owner ) 0154 { 0155 m_owner = owner; 0156 } 0157 0158 QString PhotoPluginItem::title() const 0159 { 0160 return m_title; 0161 } 0162 0163 void PhotoPluginItem::setTitle( const QString& title ) 0164 { 0165 m_title = title; 0166 m_action->setText( title ); 0167 } 0168 0169 QAction *PhotoPluginItem::action() 0170 { 0171 if( m_action->icon().isNull() ) { 0172 m_action->setIcon( QIcon( QPixmap::fromImage( m_smallImage ) ) ); 0173 } 0174 return m_action; 0175 } 0176 0177 void PhotoPluginItem::openBrowser() 0178 { 0179 if ( m_marbleWidget ) { 0180 PopupLayer* popup = m_marbleWidget->popupLayer(); 0181 popup->setCoordinates( coordinate(), Qt::AlignRight | Qt::AlignVCenter ); 0182 popup->setSize(QSizeF(720, 470)); 0183 popup->setUrl(QUrl(QLatin1String("http://m.flickr.com/photos/") + owner() + QLatin1Char('/') + id() + QLatin1Char('/'))); 0184 popup->popup(); 0185 } else { 0186 if( !m_browser ) { 0187 m_browser = new TinyWebBrowser(); 0188 } 0189 0190 QString url = "http://www.flickr.com/photos/%1/%2/"; 0191 m_browser->load( QUrl( url.arg( owner() ).arg( id() ) ) ); 0192 m_browser->show(); 0193 } 0194 } 0195 0196 #include "moc_PhotoPluginItem.cpp"