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.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #include "core/pch.h"
  11. #ifdef AUTO_UPDATE_SUPPORT
  12. #include "adjunct/autoupdate/autoupdateserverurl.h"
  13. #include "modules/prefs/prefsmanager/collections/pc_ui.h"
  14. AutoUpdateServerURL::AutoUpdateServerURL():
  15. m_current_url_no(-1)
  16. {
  17. }
  18. AutoUpdateServerURL::~AutoUpdateServerURL()
  19. {
  20. g_pcui->UnregisterListener(this);
  21. m_url_list.DeleteAll();
  22. }
  23. OP_STATUS AutoUpdateServerURL::Init()
  24. {
  25. TRAP_AND_RETURN(err, g_pcui->RegisterListenerL(this));
  26. return ReadServers();
  27. }
  28. OP_STATUS AutoUpdateServerURL::ReadServers()
  29. {
  30. OpStringC autoupdate_server_pref = g_pcui->GetStringPref(PrefsCollectionUI::AutoUpdateServer);
  31. OpString autoupdate_server;
  32. // Copy and strip any whitespace
  33. RETURN_IF_ERROR(autoupdate_server.Set(autoupdate_server_pref.CStr()));
  34. autoupdate_server.Strip();
  35. // Clear out the list
  36. m_url_list.Clear();
  37. // Add items by parsing the preference
  38. uni_char *p = autoupdate_server.CStr();
  39. uni_char *start = p;
  40. while (1)
  41. {
  42. // Look for the end marker
  43. if (*p == '\0' || *p == ' ')
  44. {
  45. OpString *server_url = OP_NEW(OpString, ());
  46. RETURN_OOM_IF_NULL(server_url);
  47. OpAutoPtr<OpString> server_url_ap(server_url);
  48. RETURN_IF_ERROR(server_url->Set(start, p - start));
  49. // Add to the internal list
  50. RETURN_IF_ERROR(m_url_list.Add(server_url));
  51. server_url_ap.release();
  52. // End of the string
  53. if (*p == '\0')
  54. break;
  55. // Move up the start
  56. start = p + 1;
  57. }
  58. p++;
  59. }
  60. if (m_url_list.GetCount() <= 0)
  61. return OpStatus::ERR;
  62. m_current_url_no = 0;
  63. return OpStatus::OK;
  64. }
  65. OP_STATUS AutoUpdateServerURL::GetCurrentURL(OpString& url)
  66. {
  67. if (m_url_list.GetCount() <= 0)
  68. return OpStatus::ERR;
  69. if (m_current_url_no < 0)
  70. return OpStatus::ERR;
  71. OP_ASSERT(m_current_url_no < (int)m_url_list.GetCount());
  72. return url.Set(m_url_list.Get(m_current_url_no)->CStr());
  73. }
  74. UINT32 AutoUpdateServerURL::GetURLCount()
  75. {
  76. return m_url_list.GetCount();
  77. }
  78. OP_STATUS AutoUpdateServerURL::IncrementURLNo(WrapType wrap)
  79. {
  80. if (m_url_list.GetCount() <= 0)
  81. return OpStatus::ERR;
  82. m_current_url_no++;
  83. if (m_current_url_no >= (int)m_url_list.GetCount())
  84. if (wrap == NoWrap)
  85. return OpStatus::ERR;
  86. else
  87. m_current_url_no = 0;
  88. return OpStatus::OK;
  89. }
  90. OP_STATUS AutoUpdateServerURL::SetURLNo(int url_number)
  91. {
  92. if (m_url_list.GetCount() <= 0)
  93. return OpStatus::ERR;
  94. if (url_number >= (int)m_url_list.GetCount())
  95. return OpStatus::ERR;
  96. if (url_number < 0)
  97. return OpStatus::ERR;
  98. m_current_url_no = url_number;
  99. return OpStatus::OK;
  100. }
  101. OP_STATUS AutoUpdateServerURL::ResetURLNo()
  102. {
  103. if (m_url_list.GetCount() <= 0)
  104. return OpStatus::ERR;
  105. m_current_url_no = 0;
  106. return OpStatus::OK;
  107. }
  108. void AutoUpdateServerURL::PrefChanged(OpPrefsCollection::Collections id, int pref, const OpStringC & newvalue)
  109. {
  110. if(OpPrefsCollection::UI != id)
  111. return;
  112. switch(PrefsCollectionUI::integerpref(pref))
  113. {
  114. case (PrefsCollectionUI::AutoUpdateServer):
  115. ReadServers();
  116. break;
  117. default:
  118. break;
  119. }
  120. }
  121. #endif // AUTO_UPDATE_SUPPORT