find tdeio plugin
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.

147 lines
4.3KB

  1. /***************************************************************************
  2. * Copyright (C) 2007 by Andreas Eckstein *
  3. * andreas.eckstein@gmx.net *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include <kdebug.h>
  21. #include <tdelocale.h>
  22. #include <tdeapplication.h>
  23. #include <dcopclient.h>
  24. #include <tdecmdlineargs.h>
  25. #include <tdeglobal.h>
  26. #include "findurl.h"
  27. #include "find.h"
  28. static const TDECmdLineOptions options[] =
  29. {
  30. { "+protocol", I18N_NOOP( "Protocol name" ), 0 },
  31. { "+pool", I18N_NOOP( "Socket name" ), 0 },
  32. { "+app", I18N_NOOP( "Socket name" ), 0 },
  33. TDECmdLineLastOption
  34. };
  35. extern "C" {
  36. int KDE_EXPORT kdemain( int argc, char **argv )
  37. {
  38. putenv(strdup("SESSION_MANAGER="));
  39. TDECmdLineArgs::init(argc, argv, "tdeio_find", 0, 0, 0, 0);
  40. TDECmdLineArgs::addCmdLineOptions( options );
  41. TDEApplication app( false, false );
  42. app.dcopClient()->attach();
  43. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  44. tdeio_findProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
  45. slave.dispatchLoop();
  46. return 0;
  47. }
  48. }
  49. tdeio_findProtocol::tdeio_findProtocol(const TQCString &protocol,
  50. const TQCString &pool, const TQCString &app)
  51. : SlaveBase(protocol, pool, app)
  52. {
  53. }
  54. tdeio_findProtocol::~tdeio_findProtocol()
  55. {
  56. }
  57. void tdeio_findProtocol::listDir(const KURL &url)
  58. {
  59. FindURL furl(url);
  60. if(furl.isMalformed())
  61. {
  62. malformedError(url, TQString("listDir"), furl);
  63. return;
  64. }
  65. if(furl.isNormalised())
  66. {
  67. redirection(KURL(furl));
  68. finished();
  69. return;
  70. }
  71. TDEIO::UDSEntry entry;
  72. TDEIO::UDSEntryList result_list;
  73. if(furl.hasSearch())
  74. {
  75. m_impl.createSearchSecondLevelEntry(entry,furl.search());
  76. listEntry(entry,false);
  77. m_impl.listSearch(furl, result_list);
  78. }
  79. else
  80. {
  81. m_impl.createTopLevelEntry(entry);
  82. listEntry(entry,false);
  83. m_impl.listSearches(result_list);
  84. }
  85. totalSize(result_list.count()+1);
  86. listEntries(result_list);
  87. entry.clear();
  88. listEntry(entry, true);
  89. finished();
  90. return;
  91. }
  92. void tdeio_findProtocol::stat(const KURL &url)
  93. {
  94. FindURL furl(url);
  95. if (furl.isMalformed())
  96. {
  97. malformedError(url, TQString("rewriteURL"), furl);
  98. return;
  99. }
  100. if(furl.isNormalised())
  101. {
  102. redirection(KURL(furl));
  103. finished();
  104. return;
  105. }
  106. if(!furl.hasSearch())
  107. {
  108. TDEIO::UDSEntry entry;
  109. m_impl.createTopLevelEntry(entry);
  110. statEntry(entry);
  111. finished();
  112. return;
  113. }
  114. TDEIO::UDSEntry entry;
  115. m_impl.createSearchSecondLevelEntry(entry , furl.search());
  116. statEntry(entry);
  117. finished();
  118. return;
  119. }
  120. void tdeio_findProtocol::malformedError(const KURL& url, TQString func, FindURL& furl)
  121. {
  122. TQString msg = url.url() + ", " + func + ", path=" + url.path() + "|search=" + furl.search() + "|filter=" + furl.filter() + "|query=" + furl.query() + "|ref=" + furl.ref();
  123. error(TDEIO::ERR_MALFORMED_URL, msg);
  124. }