• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • fileindexer
eventmonitor.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE Project
2  Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
3  Copyright (c) 2010-12 Vishesh Handa <me@vhanda.in>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "eventmonitor.h"
21 #include "fileindexerconfig.h"
22 #include "indexscheduler.h"
23 
24 #include <KDebug>
25 #include <KPassivePopup>
26 #include <KLocale>
27 #include <KDiskFreeSpaceInfo>
28 #include <KStandardDirs>
29 #include <KNotification>
30 #include <KIcon>
31 #include <KConfigGroup>
32 #include <KIdleTime>
33 
34 #include <Solid/PowerManagement>
35 
36 #include <QtDBus/QDBusInterface>
37 
38 // TODO: Make idle timeout configurable?
39 static int s_idleTimeout = 1000 * 60 * 2; // 2 min
40 static int s_availSpaceTimeout = 1000 * 30; // 30 seconds
41 
42 namespace {
43  void sendEvent( const QString& event, const QString& text, const QString& iconName ) {
44  KNotification::event( event, text, KIcon( iconName ).pixmap( 32, 32 ) );
45  }
46 }
47 
48 
49 Nepomuk2::EventMonitor::EventMonitor( QObject* parent )
50  : QObject( parent )
51 {
52  // monitor the powermanagement to not drain the battery
53  connect( Solid::PowerManagement::notifier(), SIGNAL( appShouldConserveResourcesChanged( bool ) ),
54  this, SLOT(slotPowerManagementStatusChanged(bool)) );
55 
56  // setup the avail disk usage monitor
57  connect( &m_availSpaceTimer, SIGNAL( timeout() ),
58  this, SLOT( slotCheckAvailableSpace() ) );
59 
60  // setup idle time
61  KIdleTime* idleTime = KIdleTime::instance();
62  connect( idleTime, SIGNAL(timeoutReached(int)), this, SLOT(slotIdleTimeoutReached()) );
63  connect( idleTime, SIGNAL(resumingFromIdle()), this, SLOT(slotResumeFromIdle()) );
64 
65  m_isOnBattery = Solid::PowerManagement::appShouldConserveResources();
66  m_isIdle = false;
67  m_isDiskSpaceLow = false; /* We hope */
68  m_enabled = false;
69 }
70 
71 
72 Nepomuk2::EventMonitor::~EventMonitor()
73 {
74 }
75 
76 
77 void Nepomuk2::EventMonitor::slotPowerManagementStatusChanged( bool conserveResources )
78 {
79  m_isOnBattery = conserveResources;
80  if( m_enabled ) {
81  emit powerManagementStatusChanged( conserveResources );
82  }
83 }
84 
85 
86 void Nepomuk2::EventMonitor::slotCheckAvailableSpace()
87 {
88  if( !m_enabled )
89  return;
90 
91 
92  QString path = KStandardDirs::locateLocal( "data", "nepomuk/repository/", false );
93  KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo( path );
94  if ( info.isValid() ) {
95  if ( info.available() <= FileIndexerConfig::self()->minDiskSpace() ) {
96  m_isDiskSpaceLow = true;
97  emit diskSpaceStatusChanged( true );
98 
99  sendEvent( "indexingSuspended",
100  i18n("Disk space is running low (%1 left). Suspending indexing of files.",
101  KIO::convertSize( info.available() ) ),
102  "drive-harddisk" );
103  }
104  else if( m_isDiskSpaceLow ) {
105  // We only emit this signal, if previously emitted with the value true
106  m_isDiskSpaceLow = false;
107  emit diskSpaceStatusChanged( false );
108 
109  sendEvent( "indexingResumed", i18n("Resuming indexing of files for fast searching."), "drive-harddisk" );
110  }
111  }
112  else {
113  // if it does not work once, it will probably never work
114  m_availSpaceTimer.stop();
115  }
116 }
117 
118 
119 void Nepomuk2::EventMonitor::enable()
120 {
121  /* avoid add multiple idle timeout */
122  if (!m_enabled) {
123  m_enabled = true;
124  KIdleTime::instance()->addIdleTimeout( s_idleTimeout );
125  }
126 
127  if (!m_availSpaceTimer.isActive())
128  m_availSpaceTimer.start( s_availSpaceTimeout );
129 }
130 
131 void Nepomuk2::EventMonitor::disable()
132 {
133  if (m_enabled) {
134  m_enabled = false;
135  KIdleTime::instance()->removeAllIdleTimeouts();
136  }
137 
138  m_availSpaceTimer.stop();
139 }
140 
141 void Nepomuk2::EventMonitor::suspendDiskSpaceMonitor()
142 {
143  m_availSpaceTimer.stop();
144 }
145 
146 void Nepomuk2::EventMonitor::resumeDiskSpaceMonitor()
147 {
148  if (m_enabled && !m_availSpaceTimer.isActive())
149  m_availSpaceTimer.start( s_availSpaceTimeout );
150 }
151 
152 void Nepomuk2::EventMonitor::slotIdleTimeoutReached()
153 {
154  if( m_enabled ) {
155  m_isIdle = true;
156  emit idleStatusChanged( true );
157  }
158  KIdleTime::instance()->catchNextResumeEvent();
159 }
160 
161 void Nepomuk2::EventMonitor::slotResumeFromIdle()
162 {
163  m_isIdle = false;
164  if( m_enabled ) {
165  emit idleStatusChanged( false );
166  }
167 }
168 
169 
170 #include "eventmonitor.moc"
s_availSpaceTimeout
static int s_availSpaceTimeout
Definition: eventmonitor.cpp:40
fileindexerconfig.h
indexscheduler.h
QObject
Nepomuk2::EventMonitor::resumeDiskSpaceMonitor
void resumeDiskSpaceMonitor()
Definition: eventmonitor.cpp:146
Nepomuk2::EventMonitor::disable
void disable()
Definition: eventmonitor.cpp:131
eventmonitor.h
Nepomuk2::FileIndexerConfig::minDiskSpace
KIO::filesize_t minDiskSpace() const
The minimal available disk space.
Definition: fileindexerconfig.cpp:145
Nepomuk2::EventMonitor::~EventMonitor
~EventMonitor()
Definition: eventmonitor.cpp:72
Nepomuk2::EventMonitor::enable
void enable()
Definition: eventmonitor.cpp:119
Nepomuk2::EventMonitor::suspendDiskSpaceMonitor
void suspendDiskSpaceMonitor()
Definition: eventmonitor.cpp:141
Nepomuk2::EventMonitor::EventMonitor
EventMonitor(QObject *parent=0)
Definition: eventmonitor.cpp:49
s_idleTimeout
static int s_idleTimeout
Definition: eventmonitor.cpp:39
Nepomuk2::FileIndexerConfig::self
static FileIndexerConfig * self()
Get the first created instance of FileIndexerConfig.
Definition: fileindexerconfig.cpp:82
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal