PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/LH_Weather/LH_WeatherBrowserOpener.cpp

https://code.google.com/p/lcdhost/
C++ | 84 lines | 49 code | 12 blank | 23 comment | 4 complexity | 496afa65c2ff5a1618720b58ecacd40d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. \file LH_WeatherBrowserOpener.cpp
  3. \author Andy Bridges <triscopic@codeleap.co.uk>
  4. \legalese Copyright (c) 2010 Andy Bridges
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. */
  21. #include <QDebug>
  22. #include <QPainter>
  23. #include <QDesktopServices>
  24. #include <QUrl>
  25. #include "LH_WeatherBrowserOpener.h"
  26. LH_PLUGIN_CLASS(LH_WeatherBrowserOpener)
  27. lh_class *LH_WeatherBrowserOpener::classInfo()
  28. {
  29. static lh_class classInfo =
  30. {
  31. sizeof(lh_class),
  32. "Weather",
  33. "WeatherBrowserOpener",
  34. "Weather Browser Opener",
  35. -1, -1,
  36. lh_object_calltable_NULL,
  37. lh_instance_calltable_NULL
  38. };
  39. if( classInfo.width == -1 )
  40. {
  41. QFont arial10("Arial",10);
  42. QFontMetrics fm( arial10 );
  43. classInfo.height = fm.height();
  44. classInfo.width = classInfo.height * 4;
  45. }
  46. return &classInfo;
  47. }
  48. const char *LH_WeatherBrowserOpener::userInit(){
  49. if( const char *err = LH_QtInstance::userInit() ) return err;
  50. hide();
  51. setup_browser_ = new LH_Qt_InputState(this,tr("Open in browser"),QString(),LH_FLAG_AUTORENDER);
  52. setup_browser_->setHelp("Defining a key here will allow you to open the forecast in your browser for more details");
  53. setup_browser_->setOrder(-4);
  54. connect( setup_browser_, SIGNAL(input(QString,int,int)), this, SLOT(openBrowser(QString,int,int)) );
  55. setup_json_weather_ = new LH_Qt_QString(this, "JSON Data", "", LH_FLAG_NOSOURCE | LH_FLAG_HIDDEN);
  56. setup_json_weather_->setLink("=/JSON_Weather_Data");
  57. setup_json_weather_->setMimeType("application/x-weather");
  58. return NULL;
  59. }
  60. void LH_WeatherBrowserOpener::openBrowser(QString key,int flags,int value)
  61. {
  62. Q_UNUSED(key);
  63. Q_UNUSED(flags);
  64. Q_UNUSED(value);
  65. bool ok;
  66. weatherData weather_data(setup_json_weather_->value(), ok);
  67. if( weather_data.url !="" )
  68. QDesktopServices::openUrl( QUrl::fromUserInput(weather_data.url) );
  69. }