Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autoupdateserverurl.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. *
  3. * Copyright (C) 1995-2011 Opera Software AS. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser. It may not be distributed
  6. * under any circumstances.
  7. *
  8. * @author Michal Zajaczkowski
  9. */
  10. #ifdef AUTO_UPDATE_SUPPORT
  11. #ifndef AUTOUPDATE_SERVER_URL_H
  12. #define AUTOUPDATE_SERVER_URL_H
  13. /**
  14. * This was a part of the AutoUpdateURL class.
  15. * Meant to manage the autoupdate server adresses. The opera:config#AutoUpdate|AutoupdateServer preference may hold a number of autoupdate server addresses
  16. * separated by a space character. This class parses the preference value and holds the list of available servers, making it possible to iterate trough the
  17. * list.
  18. * This comes in handy when a call to the autoupdate server fails and we want to try another server.
  19. * This is useless since there is no other server available at the moment.
  20. *
  21. * This class hold the number of "current" server, which is 0 - the first one on the list - initially. Calls to GetCurrentURL() return the current server
  22. * address. Use IncrementURLNo(), ResetURLNo(), GetURLCount() and SetURLNo() to set the current server number.
  23. * Remember that this class is meant primarily to exist in one copy hold by the AutoUpdateManager, so whenever the current server is changed, it has an
  24. * influence on every autoupdate-related functionality.
  25. *
  26. */
  27. class AutoUpdateServerURL:
  28. public OpPrefsListener
  29. {
  30. public:
  31. /**
  32. * Defines how to wrap around the server list when calling IncrementURLNo.
  33. */
  34. enum WrapType
  35. {
  36. /**
  37. * If the last server on the list has been reached, wrap the current server to the first server on the list.
  38. */
  39. Wrap,
  40. /**
  41. * If the last server on the list has been reached, don't wrap to the first one.
  42. */
  43. NoWrap
  44. };
  45. AutoUpdateServerURL();
  46. ~AutoUpdateServerURL();
  47. /**
  48. * Read the server list from the opera:config#AutoUpdate|AutoupdateServer preference and parse it, putting the result into the m_url_list vector.
  49. * This may safely be called multiple times and this is called whenever the preference changes, so changing the autoupdate server address has now
  50. * an instant effect, i.e. no browser restart is required.
  51. */
  52. OP_STATUS Init();
  53. /**
  54. * Get the current server address.
  55. *
  56. * @param url - the URL string of the current server.
  57. *
  58. * @return - OpStatus::OK when the URL string could be retrieved succesfully, ERR otherwise.
  59. */
  60. OP_STATUS GetCurrentURL(OpString& url);
  61. /**
  62. * Return the total URL server addresses count as found in the opera:config#AutoUpdate|AutoupdateServer preference value.
  63. */
  64. UINT32 GetURLCount();
  65. /**
  66. * Increment the current server number by one. Wrap through the end of the list back to the first server in case the wrap type is set to Wrap.
  67. *
  68. * @param wrap - Set to Wrap to have the list wrap over silently, set to NoWrap to receive an error if the current server is already the last one.
  69. *
  70. * @return - OpStatus::ERR if Init() did not succeed or the current server is already the last one and NoWrap was used with this call. OpStatus::OK otherwise.
  71. */
  72. OP_STATUS IncrementURLNo(WrapType wrap = NoWrap);
  73. /**
  74. * Set the current URL number directly.
  75. *
  76. * @param url_number - the url number that is to be current from now on. URL numbers start with 0.
  77. *
  78. * @return - OpStatus::ERR in case the number is negative or greater than the total URL count, or Init() did not succeed. OpStatus::OK otherwise.
  79. */
  80. OP_STATUS SetURLNo(int url_number);
  81. /**
  82. * Set the URL number back to 0.
  83. *
  84. * @return - OpStatus::ERR in case Init() did not succeed, OK otherwise.
  85. */
  86. OP_STATUS ResetURLNo();
  87. /**
  88. * OpPrefsListener implementation
  89. */
  90. void PrefChanged(OpPrefsCollection::Collections id, int pref, const OpStringC & newvalue);
  91. private:
  92. OP_STATUS ReadServers();
  93. /**
  94. * Current URL number, starting from 0 up to (m_url_count - 1).
  95. */
  96. int m_current_url_no;
  97. /**
  98. * URLs resulting from parsing the preference value are held here.
  99. */
  100. OpAutoVector<OpString> m_url_list;
  101. };
  102. #endif // AUTOUPDATE_SERVER_URL_H
  103. #endif // AUTO_UPDATE_SUPPORT