├── Makefile ├── README.md ├── everything-updatedb ├── Makefile ├── config.h ├── db.h ├── everything-updatedb.c ├── gnulib │ ├── Makefile │ ├── exitfail.c │ ├── exitfail.h │ ├── gettext.h │ ├── safe-read.c │ ├── safe-read.h │ ├── verify.h │ ├── xalloc-die.c │ ├── xalloc.h │ └── xmalloc.c ├── lib.c └── lib.h └── everything ├── EverythingForLinux.pro ├── Makefile ├── csqlquerymodel.cpp ├── csqlquerymodel.h ├── ctableview.cpp ├── ctableview.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── res.qrc ├── sudodialog.cpp ├── sudodialog.h ├── sudodialog.ui ├── taskmanager.cpp ├── taskmanager.h ├── updatedbsdialog.cpp ├── updatedbsdialog.h ├── updatedbsdialog.ui └── windowIcon.png /Makefile: -------------------------------------------------------------------------------- 1 | 2 | TARGET := bin/everything bin/everything-updatedb 3 | 4 | all: $(TARGET) 5 | 6 | bin/everything: 7 | cd everything; /usr/bin/qmake-qt4 8 | make -C everything 9 | install -D everything/EverythingForLinux $@ 10 | 11 | bin/everything-updatedb: 12 | make -C everything-updatedb 13 | install -D everything-updatedb/everything-updatedb $@ 14 | 15 | clean: 16 | make clean -C everything 17 | make clean -C everything-updatedb 18 | rm -f $(TARGET) 19 | 20 | .PHONY: all clean $(TARGET) 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EverythingForLinux 2 | Immediate search tool for linux, seems like Everything on Windows 3 | 4 | For use: 5 | make && 6 | cd bin && 7 | ./everything 8 | 9 | everything is a GUI program for search, and the everything-updatedb is a tool for updating the database for everything. 10 | 11 | Main page: 12 | http://blog.csdn.net/toormi/article/details/50879574 13 | -------------------------------------------------------------------------------- /everything-updatedb/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC = gcc 3 | LD = gcc 4 | CFLAGS = -Wall -g -c -I. -Ignulib/ 5 | LDFLAGS = -lsqlite3 6 | TAR = everything-updatedb 7 | SRC = $(wildcard *.c) 8 | OBJ = $(SRC:%.c=%.o) 9 | GNUOBJ = gnulib/xmalloc.o gnulib/xalloc-die.o gnulib/exitfail.o gnulib/safe-read.o 10 | 11 | all: $(TAR) 12 | 13 | $(TAR): $(OBJ) $(GNUOBJ) 14 | $(LD) $(OBJ) $(GNUOBJ) -o $(TAR) $(LDFLAGS) 15 | 16 | %.o: %.c 17 | $(CC) $(CFLAGS) $< -o $@ 18 | 19 | clean: 20 | rm -f *.o $(TAR) 21 | make clean -C gnulib 22 | 23 | .PHONY: all clean FORCE 24 | -------------------------------------------------------------------------------- /everything-updatedb/config.h: -------------------------------------------------------------------------------- 1 | /* src/config.h. Generated from config.h.in by configure. */ 2 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to the number of bits in type 'ptrdiff_t'. */ 5 | /* #undef BITSIZEOF_PTRDIFF_T */ 6 | 7 | /* Define to the number of bits in type 'sig_atomic_t'. */ 8 | /* #undef BITSIZEOF_SIG_ATOMIC_T */ 9 | 10 | /* Define to the number of bits in type 'size_t'. */ 11 | /* #undef BITSIZEOF_SIZE_T */ 12 | 13 | /* Define to the number of bits in type 'wchar_t'. */ 14 | /* #undef BITSIZEOF_WCHAR_T */ 15 | 16 | /* Define to the number of bits in type 'wint_t'. */ 17 | /* #undef BITSIZEOF_WINT_T */ 18 | 19 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 20 | systems. This function is required for `alloca.c' support on those systems. 21 | */ 22 | /* #undef CRAY_STACKSEG_END */ 23 | 24 | /* Define to 1 if using `alloca.c'. */ 25 | /* #undef C_ALLOCA */ 26 | 27 | /* Define to 1 if translation of program messages to the user's native 28 | language is requested. */ 29 | #define ENABLE_NLS 1 30 | 31 | /* Define to 1 when using the gnulib module fwriteerror. */ 32 | #define GNULIB_FWRITEERROR 1 33 | 34 | /* Define to 1 if you have 'alloca' after including , a header that 35 | may be supplied by this distribution. */ 36 | #define HAVE_ALLOCA 1 37 | 38 | /* Define HAVE_ALLOCA_H for backward compatibility with older code that 39 | includes only if HAVE_ALLOCA_H is defined. */ 40 | #define HAVE_ALLOCA_H 1 41 | 42 | /* Define to 1 if you have the header file. */ 43 | /* #undef HAVE_BP_SYM_H */ 44 | 45 | /* Define to 1 if you have the `btowc' function. */ 46 | #define HAVE_BTOWC 1 47 | 48 | /* Define to 1 if you have the `canonicalize_file_name' function. */ 49 | #define HAVE_CANONICALIZE_FILE_NAME 1 50 | 51 | /* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the 52 | CoreFoundation framework. */ 53 | /* #undef HAVE_CFLOCALECOPYCURRENT */ 54 | 55 | /* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in 56 | the CoreFoundation framework. */ 57 | /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */ 58 | 59 | /* Define if the GNU dcgettext() function is already present or preinstalled. 60 | */ 61 | #define HAVE_DCGETTEXT 1 62 | 63 | /* Define to 1 if you have the declaration of `canonicalize_file_name', and to 64 | 0 if you don't. */ 65 | #define HAVE_DECL_CANONICALIZE_FILE_NAME 1 66 | 67 | /* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you 68 | don't. */ 69 | #define HAVE_DECL_GETC_UNLOCKED 1 70 | 71 | /* Define to 1 if you have the declaration of `getenv', and to 0 if you don't. 72 | */ 73 | #define HAVE_DECL_GETENV 1 74 | 75 | /* Define to 1 if you have the declaration of `isblank', and to 0 if you 76 | don't. */ 77 | /* #undef HAVE_DECL_ISBLANK */ 78 | 79 | /* Define to 1 if you have the declaration of `strerror_r', and to 0 if you 80 | don't. */ 81 | #define HAVE_DECL_STRERROR_R 1 82 | 83 | /* Define to 1 if you have the declaration of `strnlen', and to 0 if you 84 | don't. */ 85 | #define HAVE_DECL_STRNLEN 1 86 | 87 | /* Define to 1 if you have the declaration of `wcwidth', and to 0 if you 88 | don't. */ 89 | #define HAVE_DECL_WCWIDTH 1 90 | 91 | /* Define to 1 if you have the `fdopendir' function. */ 92 | #define HAVE_FDOPENDIR 1 93 | 94 | /* Define to 1 if you have the `getcwd' function. */ 95 | #define HAVE_GETCWD 1 96 | 97 | /* Define to 1 if you have the `getmntent' function. */ 98 | #define HAVE_GETMNTENT 1 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #define HAVE_GETOPT_H 1 102 | 103 | /* Define to 1 if you have the `getopt_long_only' function. */ 104 | #define HAVE_GETOPT_LONG_ONLY 1 105 | 106 | /* Define if the GNU gettext() function is already present or preinstalled. */ 107 | #define HAVE_GETTEXT 1 108 | 109 | /* Define if you have the iconv() function and it works. */ 110 | /* #undef HAVE_ICONV */ 111 | 112 | /* Define if your compiler supports the #include_next directive. */ 113 | #define HAVE_INCLUDE_NEXT 1 114 | 115 | /* Define to 1 if the compiler supports one of the keywords 'inline', 116 | '__inline__', '__inline' and effectively inlines functions marked as such. 117 | */ 118 | #define HAVE_INLINE 1 119 | 120 | /* Define to 1 if you have the header file. */ 121 | #define HAVE_INTTYPES_H 1 122 | 123 | /* Define to 1 if you have the `isblank' function. */ 124 | #define HAVE_ISBLANK 1 125 | 126 | /* Define to 1 if you have the `iswcntrl' function. */ 127 | #define HAVE_ISWCNTRL 1 128 | 129 | /* Define to 1 if you have the `iswctype' function. */ 130 | #define HAVE_ISWCTYPE 1 131 | 132 | /* Define if you have and nl_langinfo(CODESET). */ 133 | #define HAVE_LANGINFO_CODESET 1 134 | 135 | /* Define to 1 if the system has the type `long long int'. */ 136 | #define HAVE_LONG_LONG_INT 1 137 | 138 | /* Define to 1 if mbrtowc and mbstate_t are properly declared. */ 139 | #define HAVE_MBRTOWC 1 140 | 141 | /* Define to 1 if you have the `mbsrtowcs' function. */ 142 | #define HAVE_MBSRTOWCS 1 143 | 144 | /* Define to 1 if declares mbstate_t. */ 145 | #define HAVE_MBSTATE_T 1 146 | 147 | /* Define to 1 if you have the `memchr' function. */ 148 | #define HAVE_MEMCHR 1 149 | 150 | /* Define to 1 if you have the header file. */ 151 | #define HAVE_MEMORY_H 1 152 | 153 | /* Define to 1 if you have the `mempcpy' function. */ 154 | #define HAVE_MEMPCPY 1 155 | 156 | /* Define to 1 if libc includes obstacks. */ 157 | #define HAVE_OBSTACK 1 158 | 159 | /* Define to 1 if you have the `readlink' function. */ 160 | #define HAVE_READLINK 1 161 | 162 | /* Define to 1 if 'sig_atomic_t' is a signed integer type. */ 163 | /* #undef HAVE_SIGNED_SIG_ATOMIC_T */ 164 | 165 | /* Define to 1 if 'wchar_t' is a signed integer type. */ 166 | /* #undef HAVE_SIGNED_WCHAR_T */ 167 | 168 | /* Define to 1 if 'wint_t' is a signed integer type. */ 169 | /* #undef HAVE_SIGNED_WINT_T */ 170 | 171 | /* Define to 1 if stdbool.h conforms to C99. */ 172 | #define HAVE_STDBOOL_H 1 173 | 174 | /* Define to 1 if you have the header file. */ 175 | #define HAVE_STDINT_H 1 176 | 177 | /* Define to 1 if you have the header file. */ 178 | #define HAVE_STDLIB_H 1 179 | 180 | /* Define to 1 if you have the `strchrnul' function. */ 181 | #define HAVE_STRCHRNUL 1 182 | 183 | /* Define to 1 if you have the `strerror' function. */ 184 | #define HAVE_STRERROR 1 185 | 186 | /* Define to 1 if you have the `strerror_r' function. */ 187 | #define HAVE_STRERROR_R 1 188 | 189 | /* Define to 1 if you have the header file. */ 190 | #define HAVE_STRINGS_H 1 191 | 192 | /* Define to 1 if you have the header file. */ 193 | #define HAVE_STRING_H 1 194 | 195 | /* Define if there is a member named d_type in the struct describing directory 196 | headers. */ 197 | #define HAVE_STRUCT_DIRENT_D_TYPE 1 198 | 199 | /* Define to 1 if `st_atimensec' is a member of `struct stat'. */ 200 | /* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */ 201 | 202 | /* Define to 1 if `st_atimespec.tv_nsec' is a member of `struct stat'. */ 203 | /* #undef HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC */ 204 | 205 | /* Define to 1 if `st_atim.st__tim.tv_nsec' is a member of `struct stat'. */ 206 | /* #undef HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC */ 207 | 208 | /* Define to 1 if `st_atim.tv_nsec' is a member of `struct stat'. */ 209 | #define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1 210 | 211 | /* Define to 1 if `st_birthtimensec' is a member of `struct stat'. */ 212 | /* #undef HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC */ 213 | 214 | /* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */ 215 | /* #undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC */ 216 | 217 | /* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */ 218 | /* #undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC */ 219 | 220 | /* Define to 1 if you have the header file. */ 221 | /* #undef HAVE_SYS_BITYPES_H */ 222 | 223 | /* Define to 1 if you have the header file. */ 224 | /* #undef HAVE_SYS_INTTYPES_H */ 225 | 226 | /* Define to 1 if you have the header file. */ 227 | #define HAVE_SYS_PARAM_H 1 228 | 229 | /* Define to 1 if you have the header file. */ 230 | #define HAVE_SYS_STAT_H 1 231 | 232 | /* Define to 1 if you have the header file. */ 233 | #define HAVE_SYS_TIME_H 1 234 | 235 | /* Define to 1 if you have the header file. */ 236 | #define HAVE_SYS_TYPES_H 1 237 | 238 | /* Define to 1 if you have the header file. */ 239 | #define HAVE_TIME_H 1 240 | 241 | /* Define to 1 if you have the header file. */ 242 | #define HAVE_UNISTD_H 1 243 | 244 | /* Define to 1 if the system has the type `unsigned long long int'. */ 245 | #define HAVE_UNSIGNED_LONG_LONG_INT 1 246 | 247 | /* Define to 1 if you have the header file. */ 248 | #define HAVE_WCHAR_H 1 249 | 250 | /* Define if you have the 'wchar_t' type. */ 251 | #define HAVE_WCHAR_T 1 252 | 253 | /* Define to 1 if you have the header file. */ 254 | #define HAVE_WCTYPE_H 1 255 | 256 | /* Define to 1 if you have the `wcwidth' function. */ 257 | #define HAVE_WCWIDTH 1 258 | 259 | /* Define if you have the 'wint_t' type. */ 260 | #define HAVE_WINT_T 1 261 | 262 | /* Define to 1 if you have the `wmemchr' function. */ 263 | #define HAVE_WMEMCHR 1 264 | 265 | /* Define to 1 if you have the `wmemcpy' function. */ 266 | #define HAVE_WMEMCPY 1 267 | 268 | /* Define to 1 if you have the `wmempcpy' function. */ 269 | #define HAVE_WMEMPCPY 1 270 | 271 | /* Define to 1 if the system has the type `_Bool'. */ 272 | #define HAVE__BOOL 1 273 | 274 | /* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */ 275 | #define MALLOC_0_IS_NONNULL 1 276 | 277 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 278 | /* #undef NO_MINUS_C_MINUS_O */ 279 | 280 | /* Define to the address where bug reports for this package should be sent. */ 281 | #define PACKAGE_BUGREPORT "mitr@redhat.com" 282 | 283 | /* Define to the full name of this package. */ 284 | #define PACKAGE_NAME "mlocate" 285 | 286 | /* Define to the full name and version of this package. */ 287 | #define PACKAGE_STRING "mlocate 0.26" 288 | 289 | /* Define to the one symbol short name of this package. */ 290 | #define PACKAGE_TARNAME "mlocate" 291 | 292 | /* Define to the home page for this package. */ 293 | #define PACKAGE_URL "https://fedorahosted.org/mlocate/" 294 | 295 | /* Define to the version of this package. */ 296 | #define PACKAGE_VERSION "0.26" 297 | 298 | /* Define to the path to the mounted filesystem table. */ 299 | #define PROC_MOUNTS_PATH "/proc/self/mounts" 300 | 301 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 302 | 'ptrdiff_t'. */ 303 | /* #undef PTRDIFF_T_SUFFIX */ 304 | 305 | /* Define this to 1 if strerror is broken. */ 306 | /* #undef REPLACE_STRERROR */ 307 | 308 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 309 | 'sig_atomic_t'. */ 310 | /* #undef SIG_ATOMIC_T_SUFFIX */ 311 | 312 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 313 | 'size_t'. */ 314 | /* #undef SIZE_T_SUFFIX */ 315 | 316 | /* If using the C implementation of alloca, define if you know the 317 | direction of stack growth for your system; otherwise it will be 318 | automatically deduced at runtime. 319 | STACK_DIRECTION > 0 => grows toward higher addresses 320 | STACK_DIRECTION < 0 => grows toward lower addresses 321 | STACK_DIRECTION = 0 => direction of growth unknown */ 322 | /* #undef STACK_DIRECTION */ 323 | 324 | /* Define to 1 if you have the ANSI C header files. */ 325 | #define STDC_HEADERS 1 326 | 327 | /* Define to 1 if strerror_r returns char *. */ 328 | #define STRERROR_R_CHAR_P 1 329 | 330 | /* Define to 1 if the type of the st_atim member of a struct stat is struct 331 | timespec. */ 332 | #define TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC 1 333 | 334 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 335 | 'wchar_t'. */ 336 | /* #undef WCHAR_T_SUFFIX */ 337 | 338 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 339 | 'wint_t'. */ 340 | /* #undef WINT_T_SUFFIX */ 341 | 342 | /* Number of bits in a file offset, on hosts where this is settable. */ 343 | /* #undef _FILE_OFFSET_BITS */ 344 | 345 | /* Define for large files, on AIX-style hosts. */ 346 | /* #undef _LARGE_FILES */ 347 | 348 | /* Define to 1 if on MINIX. */ 349 | /* #undef _MINIX */ 350 | 351 | /* Define to 2 if the system does not provide POSIX.1 features except with 352 | this defined. */ 353 | /* #undef _POSIX_1_SOURCE */ 354 | 355 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 356 | /* #undef _POSIX_SOURCE */ 357 | 358 | /* Enable extensions on AIX 3, Interix. */ 359 | #ifndef _ALL_SOURCE 360 | # define _ALL_SOURCE 1 361 | #endif 362 | /* Enable GNU extensions on systems that have them. */ 363 | #ifndef _GNU_SOURCE 364 | # define _GNU_SOURCE 1 365 | #endif 366 | /* Enable threading extensions on Solaris. */ 367 | #ifndef _POSIX_PTHREAD_SEMANTICS 368 | # define _POSIX_PTHREAD_SEMANTICS 1 369 | #endif 370 | /* Enable extensions on HP NonStop. */ 371 | #ifndef _TANDEM_SOURCE 372 | # define _TANDEM_SOURCE 1 373 | #endif 374 | /* Enable general extensions on Solaris. */ 375 | #ifndef __EXTENSIONS__ 376 | # define __EXTENSIONS__ 1 377 | #endif 378 | 379 | 380 | /* Define to rpl_ if the getopt replacement functions and variables should be 381 | used. */ 382 | /* #undef __GETOPT_PREFIX */ 383 | 384 | /* Define to a replacement function name for fnmatch(). */ 385 | /* #undef fnmatch */ 386 | 387 | /* Define to `__inline__' or `__inline' if that's what the C compiler 388 | calls it, or to nothing if 'inline' is not supported under any name. */ 389 | #ifndef __cplusplus 390 | /* #undef inline */ 391 | #endif 392 | 393 | /* Define to a type if does not define. */ 394 | /* #undef mbstate_t */ 395 | 396 | /* Define to a replacement function name for realpath(). */ 397 | /* #undef realpath */ 398 | 399 | /* Define to the equivalent of the C99 'restrict' keyword, or to 400 | nothing if this is not supported. Do not define if restrict is 401 | supported directly. */ 402 | #define restrict __restrict 403 | /* Work around a bug in Sun C++: it does not support _Restrict or 404 | __restrict__, even though the corresponding Sun C compiler ends up with 405 | "#define restrict _Restrict" or "#define restrict __restrict__" in the 406 | previous line. Perhaps some future version of Sun C++ will work with 407 | restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ 408 | #if defined __SUNPRO_CC && !defined __RESTRICT 409 | # define _Restrict 410 | # define __restrict__ 411 | #endif 412 | 413 | /* Define to `unsigned int' if does not define. */ 414 | /* #undef size_t */ 415 | 416 | /* Define as a signed type of the same size as size_t. */ 417 | /* #undef ssize_t */ 418 | 419 | /* Define to rpl_strnlen if the replacement function should be used. */ 420 | /* #undef strnlen */ 421 | -------------------------------------------------------------------------------- /everything-updatedb/db.h: -------------------------------------------------------------------------------- 1 | /* Database file format. 2 | 3 | Copyright (C) 2005 Red Hat, Inc. All rights reserved. 4 | 5 | You can use this file without restriction. 6 | 7 | This file is distributed in the hope that it will be useful, but WITHOUT ANY 8 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 9 | PARTICULAR PURPOSE. 10 | 11 | (This file defines a file format, so even the LGPL seems too restrictive. 12 | Share and enjoy.) 13 | 14 | Author: Miloslav Trmac */ 15 | 16 | #ifndef DB_H__ 17 | #define DB_H__ 18 | 19 | #include 20 | 21 | /* See doc/mlocate.db.5.in */ 22 | 23 | /* File header */ 24 | struct db_header 25 | { 26 | uint8_t magic[8]; /* See DB_MAGIC below */ 27 | uint32_t conf_size; /* Configuration block size, in big endian */ 28 | uint8_t version; /* File format version, see DB_VERSION* below */ 29 | uint8_t check_visibility; /* Check file visibility in locate(1) */ 30 | uint8_t pad[2]; /* 32-bit total alignment */ 31 | /* Followed by NUL-terminated path of the root of the database */ 32 | }; 33 | /* Followed by a configuration block and an EOF-terminated sequence of 34 | directories. 35 | 36 | The configuration block is a sequence of name-values pairs 37 | (variable name '\0' (variable value '\0')... '\0'), ordered by name. If 38 | more than one value of a variable is present, they are ordered as if by 39 | strcmp (). 40 | 41 | Directory records are not output for unreadable directories; such 42 | directories do have an entry in their parent directory. 43 | 44 | "/" does not have a parent directory, so it is not present in the database 45 | at all. */ 46 | 47 | /* Contains a '\0' byte to unambiguously mark the file as a binary file. */ 48 | #define DB_MAGIC { '\0', 'm', 'l', 'o', 'c', 'a', 't', 'e' } 49 | 50 | #define DB_VERSION_0 0x00 51 | 52 | /* Directory header */ 53 | struct db_directory 54 | { 55 | /* Both values 0 mean "invalid, always reread". This coincides with what 56 | Linux FAT, romfs and cramfs drivers do for unknown data. 57 | 58 | ctime should in theory be sufficient, but several Linux filesystems fill 59 | ctime with creation time. Therefore "time" is actually "max of ctime, 60 | mtime". */ 61 | uint64_t time_sec; /* st_[cm]time of the directory in big endian */ 62 | /* st_[cm]tim.tv_nsec of the directory in big endian or 0 if not available */ 63 | uint32_t time_nsec; 64 | uint8_t pad[4]; /* 64-bit total alignment */ 65 | /* Followed by NUL-terminated absolute path of the directory */ 66 | }; 67 | /* Followed by directory entries terminated by DBE_END, sorted by name using 68 | strcmp () */ 69 | 70 | /* Directory entry */ 71 | struct db_entry 72 | { 73 | uint8_t type; /* See DBE_* below */ 74 | /* Followed by NUL-terminated name if tag != DBE_END */ 75 | }; 76 | 77 | enum 78 | { 79 | DBE_NORMAL = 0, /* A non-directory file */ 80 | DBE_DIRECTORY = 1, /* A directory */ 81 | DBE_END = 2 /* End of directory contents; contains no name */ 82 | }; 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /everything-updatedb/everything-updatedb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "lib.h" 13 | 14 | /* Contains a single, usually not obstack_finish ()'ed object */ 15 | static struct obstack path_obstack; 16 | 17 | static struct obstack name_obstack; 18 | 19 | static bool conf_quiet; 20 | 21 | sqlite3 *g_sqlite3db; 22 | 23 | #define mlocatedb_path "/var/lib/mlocate" 24 | #define mlocatedb_name "mlocate.db" 25 | #define sqlite3db_path "/var/lib/everything" 26 | #define sqlite3db_name "everything.db" 27 | 28 | #define TABLENAME "everything" 29 | 30 | static char sql_insert[] = "INSERT INTO "TABLENAME" (NAME, PATH, TYPE) VALUES(?1, ?2, ?3);"; 31 | static char sql_create_index[] = "CREATE INDEX "TABLENAME"_idx ON "TABLENAME"(NAME);"; 32 | sqlite3_stmt *stmt; 33 | 34 | /* Statistics of the current database */ 35 | static uintmax_t stats_directories; 36 | static uintmax_t stats_entries; 37 | static uintmax_t stats_bytes; 38 | 39 | /* Clear current statistics */ 40 | static void 41 | stats_clear (void) 42 | { 43 | stats_directories = 0; 44 | stats_entries = 0; 45 | stats_bytes = 0; 46 | } 47 | 48 | int insertData(char *name, char *path, int type) 49 | { 50 | /* insert data */ 51 | sqlite3_bind_text(stmt, 1, name, strlen(name), SQLITE_STATIC); 52 | sqlite3_bind_text(stmt, 2, path, strlen(path), SQLITE_STATIC); 53 | sqlite3_bind_int(stmt, 3, type); 54 | 55 | if (sqlite3_step(stmt) != SQLITE_DONE) 56 | { 57 | fprintf(stderr, "Commit Failed!\n"); 58 | } 59 | sqlite3_reset(stmt); 60 | return 0; 61 | } 62 | 63 | /* Read and handle a directory in DB with HEADER (read just past struct 64 | db_directory); 65 | return 0 if OK, -1 on error or reached conf_output_limit 66 | 67 | path_obstack may contain a partial object if this function returns -1. */ 68 | static int handle_directory (struct db *db, const struct db_header *hdr) 69 | { 70 | size_t size, dir_name_len; 71 | int visible; 72 | void *path; 73 | void *name; 74 | 75 | stats_directories++; 76 | 77 | /* read the name of this directory */ 78 | if (db_read_name (db, &path_obstack) != 0) 79 | goto err; 80 | size = OBSTACK_OBJECT_SIZE (&path_obstack); 81 | if (size == 0) 82 | { 83 | if (conf_quiet == false) 84 | error (0, 0, _("invalid empty directory name in `%s'"), db->filename); 85 | goto err; 86 | } 87 | obstack_1grow (&path_obstack, 0); 88 | path = obstack_finish (&path_obstack); 89 | 90 | dir_name_len = OBSTACK_OBJECT_SIZE (&path_obstack); 91 | visible = hdr->check_visibility ? -1 : 1; 92 | 93 | /* read all entrise in this directory */ 94 | for (;;) 95 | { 96 | struct db_entry entry; 97 | 98 | /* read the type of entry, 0: normal file, 1: directory */ 99 | if (db_read (db, &entry, sizeof (entry)) != 0) 100 | { 101 | db_report_error (db); 102 | goto err; 103 | } 104 | if (entry.type == DBE_END) 105 | break; 106 | 107 | /* read the name of this entry */ 108 | if (db_read_name (db, &name_obstack) != 0) 109 | goto err; 110 | obstack_1grow(&name_obstack, 0); 111 | 112 | /* insert this entry info in sqlite3 database, include filename, path, type(file or not) */ 113 | insertData(obstack_base(&name_obstack), path, entry.type); 114 | 115 | /* clear name_obstack */ 116 | size = OBSTACK_OBJECT_SIZE (&name_obstack); 117 | if (size > OBSTACK_SIZE_MAX) /* No surprises, please */ 118 | { 119 | if (conf_quiet == false) 120 | error (0, 0, _("file name length %zu in `%s' is too large"), size, 121 | db->filename); 122 | goto err; 123 | } 124 | obstack_blank (&name_obstack, -(ssize_t)size); 125 | } 126 | name = obstack_finish(&name_obstack); 127 | obstack_free (&path_obstack, path); 128 | obstack_free (&name_obstack, name); 129 | return 0; 130 | 131 | err: 132 | return -1; 133 | } 134 | 135 | 136 | static void handle_db (int fd, const char *database) 137 | { 138 | struct db db; 139 | struct db_header hdr; 140 | struct db_directory dir; 141 | void *p; 142 | int visible; 143 | 144 | /* open locate db */ 145 | if (db_open (&db, &hdr, fd, database, conf_quiet) != 0) 146 | { 147 | close(fd); 148 | goto err; 149 | } 150 | stats_clear (); 151 | 152 | /* read "/" */ 153 | if (db_read_name (&db, &path_obstack) != 0) 154 | goto err_path; 155 | obstack_1grow (&path_obstack, 0); 156 | visible = hdr.check_visibility ? -1 : 1; 157 | p = obstack_finish (&path_obstack); 158 | obstack_free (&path_obstack, p); 159 | 160 | /* skip configure block */ 161 | if (db_skip (&db, ntohl (hdr.conf_size)) != 0) 162 | goto err_path; 163 | 164 | /* transaction begin */ 165 | fprintf(stdout, "Begin translation...\n"); 166 | sqlite3_exec(g_sqlite3db, "BEGIN TRANSACTION", NULL, NULL, NULL); 167 | sqlite3_prepare_v2(g_sqlite3db, sql_insert, strlen(sql_insert), &stmt, NULL); 168 | 169 | /* read all directories */ 170 | while (db_read (&db, &dir, sizeof (dir)) == 0) 171 | { 172 | /* read all in this directory, and store them in sqlit3 db */ 173 | if (handle_directory (&db, &hdr) != 0) 174 | goto err_path; 175 | } 176 | 177 | /* create index on table(NAME) */ 178 | sqlite3_exec(g_sqlite3db, sql_create_index, NULL, NULL, NULL); 179 | 180 | /* transaction end */ 181 | sqlite3_exec(g_sqlite3db, "COMMIT TRANSACTION", NULL, NULL, NULL); 182 | sqlite3_finalize(stmt); 183 | 184 | fprintf(stdout, "Translation completely\n"); 185 | 186 | if (db.err != 0) 187 | { 188 | db_report_error (&db); 189 | goto err_path; 190 | } 191 | /* Fall through */ 192 | err_path: 193 | p = obstack_finish (&path_obstack); 194 | err_free: 195 | obstack_free (&path_obstack, p); 196 | db_close (&db); 197 | err: 198 | ; 199 | } 200 | 201 | static void handle_mlocatedb_path_entry (const char *entry) 202 | { 203 | int fd; 204 | 205 | struct stat st; 206 | 207 | if (stat (entry, &st) != 0) 208 | { 209 | if (conf_quiet == false) 210 | error (0, errno, _("can not stat () `%s'"), entry); 211 | goto err; 212 | } 213 | fd = open (entry, O_RDONLY); 214 | if (fd == -1) 215 | { 216 | if (conf_quiet == false) 217 | error (0, errno, _("can not open `%s'"), entry); 218 | goto err; 219 | } 220 | if (fstat (fd, &st) != 0) 221 | { 222 | if (conf_quiet == false) 223 | error (0, errno, _("can not stat () `%s'"), entry); 224 | close (fd); 225 | goto err; 226 | } 227 | 228 | /* locate database is ok, handle it */ 229 | handle_db (fd, entry); /* Closes fd */ 230 | err: 231 | ; 232 | } 233 | 234 | int disconnect_sqlite3db() 235 | { 236 | sqlite3_close(g_sqlite3db); 237 | } 238 | 239 | int connect_sqlite3db() 240 | { 241 | /* connect everything database */ 242 | char *zErrMsg = 0; 243 | int rc; 244 | 245 | DIR *dir; 246 | if ((dir = opendir(sqlite3db_path)) == NULL) 247 | { 248 | if (mkdir(sqlite3db_path, 0755) == -1) 249 | { 250 | closedir(dir); 251 | return -1; 252 | } 253 | } 254 | closedir(dir); 255 | 256 | if (unlink(sqlite3db_path"/"sqlite3db_name) == -1) 257 | { 258 | fprintf(stderr, "Can't remove database: %s\n", sqlite3db_path"/"sqlite3db_name); 259 | } 260 | 261 | rc = sqlite3_open(sqlite3db_path"/"sqlite3db_name, &g_sqlite3db); 262 | if (rc) 263 | { 264 | fprintf(stderr, "Can't open database: %s\n", sqlite3db_path"/"sqlite3db_name); 265 | return -1; 266 | } 267 | else 268 | { 269 | fprintf(stdout, "Open database successfully\n"); 270 | } 271 | 272 | /* create table */ 273 | char *sql = "CREATE TABLE "TABLENAME"(" 274 | "ID INTEGER PRIMARY KEY NOT NULL," 275 | "NAME TEXT NOT NULL," 276 | "PATH INTEGER NOT NULL," 277 | "TYPE INTEGER NOT NULL);"; 278 | rc = sqlite3_exec(g_sqlite3db, sql, NULL, 0, &zErrMsg); 279 | if (rc != SQLITE_OK) 280 | { 281 | fprintf(stderr, "SQL error: %s\n", zErrMsg); 282 | sqlite3_free(zErrMsg); 283 | return -1; 284 | } 285 | else 286 | { 287 | fprintf(stdout, "Create table successfully\n"); 288 | } 289 | 290 | return 0; 291 | } 292 | 293 | static void help() 294 | { 295 | printf("Usage: everything-updatedb [OPTION]\n" 296 | "Update the database used by everything.\n" 297 | "\n" 298 | "-h print this help\n" 299 | "\n" 300 | "Report bugs to mamingliang1990@163.com.\n" 301 | ); 302 | } 303 | 304 | int main(int argc, char *argv[]) 305 | { 306 | if (argc == 2 && strcmp(argv[1] ,"-h") == 0) 307 | { 308 | help(); 309 | exit(EXIT_SUCCESS); 310 | } 311 | 312 | if (connect_sqlite3db() != 0) 313 | { 314 | fprintf(stderr, "Connect everything database error!\n"); 315 | exit(EXIT_FAILURE); 316 | } 317 | 318 | obstack_init(&path_obstack); 319 | obstack_init(&name_obstack); 320 | 321 | obstack_alignment_mask(&path_obstack) = 0; 322 | 323 | handle_mlocatedb_path_entry(mlocatedb_path"/"mlocatedb_name); 324 | 325 | disconnect_sqlite3db(); 326 | exit(EXIT_SUCCESS); 327 | } 328 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CC = gcc 3 | LD = gcc 4 | CFLAGS = -Wall -g -c -I.. 5 | SRC = $(wildcard *.c) 6 | OBJ = $(SRC:%.c=%.o) 7 | 8 | all: $(OBJ) 9 | 10 | %.o: %.c 11 | $(CC) $(CFLAGS) $< -o $@ 12 | 13 | clean: 14 | rm -f *.o 15 | 16 | .PHONY: 17 | all clean 18 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/exitfail.c: -------------------------------------------------------------------------------- 1 | /* Failure exit status 2 | 3 | Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. 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, or (at your option) 8 | 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; see the file COPYING. 17 | If not, write to the Free Software Foundation, 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 | 20 | #include 21 | 22 | #include "exitfail.h" 23 | 24 | #include 25 | 26 | int volatile exit_failure = EXIT_FAILURE; 27 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/exitfail.h: -------------------------------------------------------------------------------- 1 | /* Failure exit status 2 | 3 | Copyright (C) 2002 Free Software Foundation, Inc. 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, or (at your option) 8 | 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; see the file COPYING. 17 | If not, write to the Free Software Foundation, 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 | 20 | extern int volatile exit_failure; 21 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/gettext.h: -------------------------------------------------------------------------------- 1 | /* Convenience header for conditional use of GNU . 2 | Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program 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 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License along 15 | with this program; if not, write to the Free Software Foundation, 16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 | 18 | #ifndef _LIBGETTEXT_H 19 | #define _LIBGETTEXT_H 1 20 | 21 | /* NLS can be disabled through the configure --disable-nls option. */ 22 | #if ENABLE_NLS 23 | 24 | /* Get declarations of GNU message catalog functions. */ 25 | # include 26 | 27 | /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by 28 | the gettext() and ngettext() macros. This is an alternative to calling 29 | textdomain(), and is useful for libraries. */ 30 | # ifdef DEFAULT_TEXT_DOMAIN 31 | # undef gettext 32 | # define gettext(Msgid) \ 33 | dgettext (DEFAULT_TEXT_DOMAIN, Msgid) 34 | # undef ngettext 35 | # define ngettext(Msgid1, Msgid2, N) \ 36 | dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) 37 | # endif 38 | 39 | #else 40 | 41 | /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which 42 | chokes if dcgettext is defined as a macro. So include it now, to make 43 | later inclusions of a NOP. We don't include 44 | as well because people using "gettext.h" will not include , 45 | and also including would fail on SunOS 4, whereas 46 | is OK. */ 47 | #if defined(__sun) 48 | # include 49 | #endif 50 | 51 | /* Many header files from the libstdc++ coming with g++ 3.3 or newer include 52 | , which chokes if dcgettext is defined as a macro. So include 53 | it now, to make later inclusions of a NOP. */ 54 | #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) 55 | # include 56 | # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H 57 | # include 58 | # endif 59 | #endif 60 | 61 | /* Disabled NLS. 62 | The casts to 'const char *' serve the purpose of producing warnings 63 | for invalid uses of the value returned from these functions. 64 | On pre-ANSI systems without 'const', the config.h file is supposed to 65 | contain "#define const". */ 66 | # define gettext(Msgid) ((const char *) (Msgid)) 67 | # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) 68 | # define dcgettext(Domainname, Msgid, Category) \ 69 | ((void) (Category), dgettext (Domainname, Msgid)) 70 | # define ngettext(Msgid1, Msgid2, N) \ 71 | ((N) == 1 \ 72 | ? ((void) (Msgid2), (const char *) (Msgid1)) \ 73 | : ((void) (Msgid1), (const char *) (Msgid2))) 74 | # define dngettext(Domainname, Msgid1, Msgid2, N) \ 75 | ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) 76 | # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 77 | ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) 78 | # define textdomain(Domainname) ((const char *) (Domainname)) 79 | # define bindtextdomain(Domainname, Dirname) \ 80 | ((void) (Domainname), (const char *) (Dirname)) 81 | # define bind_textdomain_codeset(Domainname, Codeset) \ 82 | ((void) (Domainname), (const char *) (Codeset)) 83 | 84 | #endif 85 | 86 | /* A pseudo function call that serves as a marker for the automated 87 | extraction of messages, but does not call gettext(). The run-time 88 | translation is done at a different place in the code. 89 | The argument, String, should be a literal string. Concatenated strings 90 | and other string expressions won't work. 91 | The macro's expansion is not parenthesized, so that it is suitable as 92 | initializer for static 'char[]' or 'const char[]' variables. */ 93 | #define gettext_noop(String) String 94 | 95 | /* The separator between msgctxt and msgid in a .mo file. */ 96 | #define GETTEXT_CONTEXT_GLUE "\004" 97 | 98 | /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a 99 | MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be 100 | short and rarely need to change. 101 | The letter 'p' stands for 'particular' or 'special'. */ 102 | #ifdef DEFAULT_TEXT_DOMAIN 103 | # define pgettext(Msgctxt, Msgid) \ 104 | pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 105 | #else 106 | # define pgettext(Msgctxt, Msgid) \ 107 | pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 108 | #endif 109 | #define dpgettext(Domainname, Msgctxt, Msgid) \ 110 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) 111 | #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ 112 | pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) 113 | #ifdef DEFAULT_TEXT_DOMAIN 114 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ 115 | npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 116 | #else 117 | # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ 118 | npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 119 | #endif 120 | #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 121 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) 122 | #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ 123 | npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) 124 | 125 | #ifdef __GNUC__ 126 | __inline 127 | #else 128 | #ifdef __cplusplus 129 | inline 130 | #endif 131 | #endif 132 | static const char * 133 | pgettext_aux (const char *domain, 134 | const char *msg_ctxt_id, const char *msgid, 135 | int category) 136 | { 137 | const char *translation = dcgettext (domain, msg_ctxt_id, category); 138 | if (translation == msg_ctxt_id) 139 | return msgid; 140 | else 141 | return translation; 142 | } 143 | 144 | #ifdef __GNUC__ 145 | __inline 146 | #else 147 | #ifdef __cplusplus 148 | inline 149 | #endif 150 | #endif 151 | static const char * 152 | npgettext_aux (const char *domain, 153 | const char *msg_ctxt_id, const char *msgid, 154 | const char *msgid_plural, unsigned long int n, 155 | int category) 156 | { 157 | const char *translation = 158 | dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 159 | if (translation == msg_ctxt_id || translation == msgid_plural) 160 | return (n == 1 ? msgid : msgid_plural); 161 | else 162 | return translation; 163 | } 164 | 165 | /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID 166 | can be arbitrary expressions. But for string literals these macros are 167 | less efficient than those above. */ 168 | 169 | #include 170 | 171 | #define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ 172 | (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ 173 | /* || __STDC_VERSION__ >= 199901L */ ) 174 | 175 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 176 | #include 177 | #endif 178 | 179 | #define pgettext_expr(Msgctxt, Msgid) \ 180 | dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) 181 | #define dpgettext_expr(Domainname, Msgctxt, Msgid) \ 182 | dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) 183 | 184 | #ifdef __GNUC__ 185 | __inline 186 | #else 187 | #ifdef __cplusplus 188 | inline 189 | #endif 190 | #endif 191 | static const char * 192 | dcpgettext_expr (const char *domain, 193 | const char *msgctxt, const char *msgid, 194 | int category) 195 | { 196 | size_t msgctxt_len = strlen (msgctxt) + 1; 197 | size_t msgid_len = strlen (msgid) + 1; 198 | const char *translation; 199 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 200 | char msg_ctxt_id[msgctxt_len + msgid_len]; 201 | #else 202 | char buf[1024]; 203 | char *msg_ctxt_id = 204 | (msgctxt_len + msgid_len <= sizeof (buf) 205 | ? buf 206 | : (char *) malloc (msgctxt_len + msgid_len)); 207 | if (msg_ctxt_id != NULL) 208 | #endif 209 | { 210 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 211 | msg_ctxt_id[msgctxt_len - 1] = '\004'; 212 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 213 | translation = dcgettext (domain, msg_ctxt_id, category); 214 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 215 | if (msg_ctxt_id != buf) 216 | free (msg_ctxt_id); 217 | #endif 218 | if (translation != msg_ctxt_id) 219 | return translation; 220 | } 221 | return msgid; 222 | } 223 | 224 | #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ 225 | dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 226 | #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ 227 | dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) 228 | 229 | #ifdef __GNUC__ 230 | __inline 231 | #else 232 | #ifdef __cplusplus 233 | inline 234 | #endif 235 | #endif 236 | static const char * 237 | dcnpgettext_expr (const char *domain, 238 | const char *msgctxt, const char *msgid, 239 | const char *msgid_plural, unsigned long int n, 240 | int category) 241 | { 242 | size_t msgctxt_len = strlen (msgctxt) + 1; 243 | size_t msgid_len = strlen (msgid) + 1; 244 | const char *translation; 245 | #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 246 | char msg_ctxt_id[msgctxt_len + msgid_len]; 247 | #else 248 | char buf[1024]; 249 | char *msg_ctxt_id = 250 | (msgctxt_len + msgid_len <= sizeof (buf) 251 | ? buf 252 | : (char *) malloc (msgctxt_len + msgid_len)); 253 | if (msg_ctxt_id != NULL) 254 | #endif 255 | { 256 | memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 257 | msg_ctxt_id[msgctxt_len - 1] = '\004'; 258 | memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 259 | translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 260 | #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 261 | if (msg_ctxt_id != buf) 262 | free (msg_ctxt_id); 263 | #endif 264 | if (!(translation == msg_ctxt_id || translation == msgid_plural)) 265 | return translation; 266 | } 267 | return (n == 1 ? msgid : msgid_plural); 268 | } 269 | 270 | #endif /* _LIBGETTEXT_H */ 271 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/safe-read.c: -------------------------------------------------------------------------------- 1 | /* An interface to read and write that retries after interrupts. 2 | 3 | Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004, 2005, 2006 Free 4 | Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 | 20 | #include 21 | 22 | /* Specification. */ 23 | #ifdef SAFE_WRITE 24 | # include "safe-write.h" 25 | #else 26 | # include "safe-read.h" 27 | #endif 28 | 29 | /* Get ssize_t. */ 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #ifdef EINTR 36 | # define IS_EINTR(x) ((x) == EINTR) 37 | #else 38 | # define IS_EINTR(x) 0 39 | #endif 40 | 41 | #include 42 | 43 | #ifdef SAFE_WRITE 44 | # define safe_rw safe_write 45 | # define rw write 46 | #else 47 | # define safe_rw safe_read 48 | # define rw read 49 | # undef const 50 | # define const /* empty */ 51 | #endif 52 | 53 | /* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if 54 | interrupted. Return the actual number of bytes read(written), zero for EOF, 55 | or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */ 56 | size_t 57 | safe_rw (int fd, void const *buf, size_t count) 58 | { 59 | /* Work around a bug in Tru64 5.1. Attempting to read more than 60 | INT_MAX bytes fails with errno == EINVAL. See 61 | . 62 | When decreasing COUNT, keep it block-aligned. */ 63 | enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 }; 64 | 65 | for (;;) 66 | { 67 | ssize_t result = rw (fd, buf, count); 68 | 69 | if (0 <= result) 70 | return result; 71 | else if (IS_EINTR (errno)) 72 | continue; 73 | else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) 74 | count = BUGGY_READ_MAXIMUM; 75 | else 76 | return result; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/safe-read.h: -------------------------------------------------------------------------------- 1 | /* An interface to read() that retries after interrupts. 2 | Copyright (C) 2002, 2006 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2, or (at your option) 7 | any later version. 8 | 9 | This program 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 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software Foundation, 16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | #define SAFE_READ_ERROR ((size_t) -1) 26 | 27 | /* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted. 28 | Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR 29 | upon error. */ 30 | extern size_t safe_read (int fd, void *buf, size_t count); 31 | 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/verify.h: -------------------------------------------------------------------------------- 1 | /* Compile-time assert-like macros. 2 | 3 | Copyright (C) 2005, 2006 Free Software Foundation, Inc. 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, or (at your option) 8 | 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 Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ 20 | 21 | #ifndef VERIFY_H 22 | # define VERIFY_H 1 23 | 24 | /* Each of these macros verifies that its argument R is nonzero. To 25 | be portable, R should be an integer constant expression. Unlike 26 | assert (R), there is no run-time overhead. 27 | 28 | There are two macros, since no single macro can be used in all 29 | contexts in C. verify_true (R) is for scalar contexts, including 30 | integer constant expression contexts. verify (R) is for declaration 31 | contexts, e.g., the top level. 32 | 33 | Symbols ending in "__" are private to this header. 34 | 35 | The code below uses several ideas. 36 | 37 | * The first step is ((R) ? 1 : -1). Given an expression R, of 38 | integral or boolean or floating-point type, this yields an 39 | expression of integral type, whose value is later verified to be 40 | constant and nonnegative. 41 | 42 | * Next this expression W is wrapped in a type 43 | struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }. 44 | If W is negative, this yields a compile-time error. No compiler can 45 | deal with a bit-field of negative size. 46 | 47 | One might think that an array size check would have the same 48 | effect, that is, that the type struct { unsigned int dummy[W]; } 49 | would work as well. However, inside a function, some compilers 50 | (such as C++ compilers and GNU C) allow local parameters and 51 | variables inside array size expressions. With these compilers, 52 | an array size check would not properly diagnose this misuse of 53 | the verify macro: 54 | 55 | void function (int n) { verify (n < 0); } 56 | 57 | * For the verify macro, the struct verify_type__ will need to 58 | somehow be embedded into a declaration. To be portable, this 59 | declaration must declare an object, a constant, a function, or a 60 | typedef name. If the declared entity uses the type directly, 61 | such as in 62 | 63 | struct dummy {...}; 64 | typedef struct {...} dummy; 65 | extern struct {...} *dummy; 66 | extern void dummy (struct {...} *); 67 | extern struct {...} *dummy (void); 68 | 69 | two uses of the verify macro would yield colliding declarations 70 | if the entity names are not disambiguated. A workaround is to 71 | attach the current line number to the entity name: 72 | 73 | #define GL_CONCAT0(x, y) x##y 74 | #define GL_CONCAT(x, y) GL_CONCAT0 (x, y) 75 | extern struct {...} * GL_CONCAT(dummy,__LINE__); 76 | 77 | But this has the problem that two invocations of verify from 78 | within the same macro would collide, since the __LINE__ value 79 | would be the same for both invocations. 80 | 81 | A solution is to use the sizeof operator. It yields a number, 82 | getting rid of the identity of the type. Declarations like 83 | 84 | extern int dummy [sizeof (struct {...})]; 85 | extern void dummy (int [sizeof (struct {...})]); 86 | extern int (*dummy (void)) [sizeof (struct {...})]; 87 | 88 | can be repeated. 89 | 90 | * Should the implementation use a named struct or an unnamed struct? 91 | Which of the following alternatives can be used? 92 | 93 | extern int dummy [sizeof (struct {...})]; 94 | extern int dummy [sizeof (struct verify_type__ {...})]; 95 | extern void dummy (int [sizeof (struct {...})]); 96 | extern void dummy (int [sizeof (struct verify_type__ {...})]); 97 | extern int (*dummy (void)) [sizeof (struct {...})]; 98 | extern int (*dummy (void)) [sizeof (struct verify_type__ {...})]; 99 | 100 | In the second and sixth case, the struct type is exported to the 101 | outer scope; two such declarations therefore collide. GCC warns 102 | about the first, third, and fourth cases. So the only remaining 103 | possibility is the fifth case: 104 | 105 | extern int (*dummy (void)) [sizeof (struct {...})]; 106 | 107 | * This implementation exploits the fact that GCC does not warn about 108 | the last declaration mentioned above. If a future version of GCC 109 | introduces a warning for this, the problem could be worked around 110 | by using code specialized to GCC, e.g.,: 111 | 112 | #if 4 <= __GNUC__ 113 | # define verify(R) \ 114 | extern int (* verify_function__ (void)) \ 115 | [__builtin_constant_p (R) && (R) ? 1 : -1] 116 | #endif 117 | 118 | * In C++, any struct definition inside sizeof is invalid. 119 | Use a template type to work around the problem. */ 120 | 121 | 122 | /* Verify requirement R at compile-time, as an integer constant expression. 123 | Return 1. */ 124 | 125 | # ifdef __cplusplus 126 | template 127 | struct verify_type__ { unsigned int verify_error_if_negative_size__: w; }; 128 | # define verify_true(R) \ 129 | (!!sizeof (verify_type__<(R) ? 1 : -1>)) 130 | # else 131 | # define verify_true(R) \ 132 | (!!sizeof \ 133 | (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; })) 134 | # endif 135 | 136 | /* Verify requirement R at compile-time, as a declaration without a 137 | trailing ';'. */ 138 | 139 | # define verify(R) extern int (* verify_function__ (void)) [verify_true (R)] 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/xalloc-die.c: -------------------------------------------------------------------------------- 1 | /* Report a memory allocation failure and exit. 2 | 3 | Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free 4 | Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 | 20 | #include 21 | 22 | #include "xalloc.h" 23 | 24 | #include 25 | 26 | #include "error.h" 27 | #include "exitfail.h" 28 | 29 | #include "gettext.h" 30 | #define _(msgid) gettext (msgid) 31 | 32 | void 33 | xalloc_die (void) 34 | { 35 | error (exit_failure, 0, "%s", _("memory exhausted")); 36 | 37 | /* The `noreturn' cannot be given to error, since it may return if 38 | its first argument is 0. To help compilers understand the 39 | xalloc_die does not return, call abort. Also, the abort is a 40 | safety feature if exit_failure is 0 (which shouldn't happen). */ 41 | abort (); 42 | } 43 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/xalloc.h: -------------------------------------------------------------------------------- 1 | /* xalloc.h -- malloc with out-of-memory checking 2 | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 4 | 1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2, or (at your option) 9 | any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 | 20 | #ifndef XALLOC_H_ 21 | # define XALLOC_H_ 22 | 23 | # include 24 | 25 | 26 | # ifdef __cplusplus 27 | extern "C" { 28 | # endif 29 | 30 | 31 | # ifndef __attribute__ 32 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ 33 | # define __attribute__(x) 34 | # endif 35 | # endif 36 | 37 | # ifndef ATTRIBUTE_NORETURN 38 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 39 | # endif 40 | 41 | /* This function is always triggered when memory is exhausted. 42 | It must be defined by the application, either explicitly 43 | or by using gnulib's xalloc-die module. This is the 44 | function to call when one wants the program to die because of a 45 | memory allocation failure. */ 46 | extern void xalloc_die (void) ATTRIBUTE_NORETURN; 47 | 48 | void *xmalloc (size_t s); 49 | void *xzalloc (size_t s); 50 | void *xcalloc (size_t n, size_t s); 51 | void *xrealloc (void *p, size_t s); 52 | void *x2realloc (void *p, size_t *pn); 53 | void *xmemdup (void const *p, size_t s); 54 | char *xstrdup (char const *str); 55 | 56 | /* Return 1 if an array of N objects, each of size S, cannot exist due 57 | to size arithmetic overflow. S must be positive and N must be 58 | nonnegative. This is a macro, not an inline function, so that it 59 | works correctly even when SIZE_MAX < N. 60 | 61 | By gnulib convention, SIZE_MAX represents overflow in size 62 | calculations, so the conservative dividend to use here is 63 | SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. 64 | However, malloc (SIZE_MAX) fails on all known hosts where 65 | sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for 66 | exactly-SIZE_MAX allocations on such hosts; this avoids a test and 67 | branch when S is known to be 1. */ 68 | # define xalloc_oversized(n, s) \ 69 | ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) 70 | 71 | 72 | /* In the following macros, T must be an elementary or structure/union or 73 | typedef'ed type, or a pointer to such a type. To apply one of the 74 | following macros to a function pointer or array type, you need to typedef 75 | it first and use the typedef name. */ 76 | 77 | /* Allocate an object of type T dynamically, with error checking. */ 78 | /* extern t *XMALLOC (typename t); */ 79 | # define XMALLOC(t) ((t *) xmalloc (sizeof (t))) 80 | 81 | /* Allocate memory for N elements of type T, with error checking. */ 82 | /* extern t *XNMALLOC (size_t n, typename t); */ 83 | # define XNMALLOC(n, t) \ 84 | ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) 85 | 86 | /* Allocate an object of type T dynamically, with error checking, 87 | and zero it. */ 88 | /* extern t *XZALLOC (typename t); */ 89 | # define XZALLOC(t) ((t *) xzalloc (sizeof (t))) 90 | 91 | /* Allocate memory for N elements of type T, with error checking, 92 | and zero it. */ 93 | /* extern t *XCALLOC (size_t n, typename t); */ 94 | # define XCALLOC(n, t) \ 95 | ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) 96 | 97 | 98 | # if HAVE_INLINE 99 | # define static_inline static inline 100 | # else 101 | void *xnmalloc (size_t n, size_t s); 102 | void *xnrealloc (void *p, size_t n, size_t s); 103 | void *x2nrealloc (void *p, size_t *pn, size_t s); 104 | char *xcharalloc (size_t n); 105 | # endif 106 | 107 | # ifdef static_inline 108 | 109 | /* Allocate an array of N objects, each with S bytes of memory, 110 | dynamically, with error checking. S must be nonzero. */ 111 | 112 | static_inline void * 113 | xnmalloc (size_t n, size_t s) 114 | { 115 | if (xalloc_oversized (n, s)) 116 | xalloc_die (); 117 | return xmalloc (n * s); 118 | } 119 | 120 | /* Change the size of an allocated block of memory P to an array of N 121 | objects each of S bytes, with error checking. S must be nonzero. */ 122 | 123 | static_inline void * 124 | xnrealloc (void *p, size_t n, size_t s) 125 | { 126 | if (xalloc_oversized (n, s)) 127 | xalloc_die (); 128 | return xrealloc (p, n * s); 129 | } 130 | 131 | /* If P is null, allocate a block of at least *PN such objects; 132 | otherwise, reallocate P so that it contains more than *PN objects 133 | each of S bytes. *PN must be nonzero unless P is null, and S must 134 | be nonzero. Set *PN to the new number of objects, and return the 135 | pointer to the new block. *PN is never set to zero, and the 136 | returned pointer is never null. 137 | 138 | Repeated reallocations are guaranteed to make progress, either by 139 | allocating an initial block with a nonzero size, or by allocating a 140 | larger block. 141 | 142 | In the following implementation, nonzero sizes are increased by a 143 | factor of approximately 1.5 so that repeated reallocations have 144 | O(N) overall cost rather than O(N**2) cost, but the 145 | specification for this function does not guarantee that rate. 146 | 147 | Here is an example of use: 148 | 149 | int *p = NULL; 150 | size_t used = 0; 151 | size_t allocated = 0; 152 | 153 | void 154 | append_int (int value) 155 | { 156 | if (used == allocated) 157 | p = x2nrealloc (p, &allocated, sizeof *p); 158 | p[used++] = value; 159 | } 160 | 161 | This causes x2nrealloc to allocate a block of some nonzero size the 162 | first time it is called. 163 | 164 | To have finer-grained control over the initial size, set *PN to a 165 | nonzero value before calling this function with P == NULL. For 166 | example: 167 | 168 | int *p = NULL; 169 | size_t used = 0; 170 | size_t allocated = 0; 171 | size_t allocated1 = 1000; 172 | 173 | void 174 | append_int (int value) 175 | { 176 | if (used == allocated) 177 | { 178 | p = x2nrealloc (p, &allocated1, sizeof *p); 179 | allocated = allocated1; 180 | } 181 | p[used++] = value; 182 | } 183 | 184 | */ 185 | 186 | static_inline void * 187 | x2nrealloc (void *p, size_t *pn, size_t s) 188 | { 189 | size_t n = *pn; 190 | 191 | if (! p) 192 | { 193 | if (! n) 194 | { 195 | /* The approximate size to use for initial small allocation 196 | requests, when the invoking code specifies an old size of 197 | zero. 64 bytes is the largest "small" request for the 198 | GNU C library malloc. */ 199 | enum { DEFAULT_MXFAST = 64 }; 200 | 201 | n = DEFAULT_MXFAST / s; 202 | n += !n; 203 | } 204 | } 205 | else 206 | { 207 | /* Set N = ceil (1.5 * N) so that progress is made if N == 1. 208 | Check for overflow, so that N * S stays in size_t range. 209 | The check is slightly conservative, but an exact check isn't 210 | worth the trouble. */ 211 | if ((size_t) -1 / 3 * 2 / s <= n) 212 | xalloc_die (); 213 | n += (n + 1) / 2; 214 | } 215 | 216 | *pn = n; 217 | return xrealloc (p, n * s); 218 | } 219 | 220 | /* Return a pointer to a new buffer of N bytes. This is like xmalloc, 221 | except it returns char *. */ 222 | 223 | static_inline char * 224 | xcharalloc (size_t n) 225 | { 226 | return XNMALLOC (n, char); 227 | } 228 | 229 | # endif 230 | 231 | # ifdef __cplusplus 232 | } 233 | 234 | /* C++ does not allow conversions from void * to other pointer types 235 | without a cast. Use templates to work around the problem when 236 | possible. */ 237 | 238 | template inline T * 239 | xrealloc (T *p, size_t s) 240 | { 241 | return (T *) xrealloc ((void *) p, s); 242 | } 243 | 244 | template inline T * 245 | xnrealloc (T *p, size_t n, size_t s) 246 | { 247 | return (T *) xnrealloc ((void *) p, n, s); 248 | } 249 | 250 | template inline T * 251 | x2realloc (T *p, size_t *pn) 252 | { 253 | return (T *) x2realloc ((void *) p, pn); 254 | } 255 | 256 | template inline T * 257 | x2nrealloc (T *p, size_t *pn, size_t s) 258 | { 259 | return (T *) x2nrealloc ((void *) p, pn, s); 260 | } 261 | 262 | template inline T * 263 | xmemdup (T const *p, size_t s) 264 | { 265 | return (T *) xmemdup ((void const *) p, s); 266 | } 267 | 268 | # endif 269 | 270 | 271 | #endif /* !XALLOC_H_ */ 272 | -------------------------------------------------------------------------------- /everything-updatedb/gnulib/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* xmalloc.c -- malloc with out of memory checking 2 | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 4 | 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, 5 | Inc. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2, or (at your option) 10 | any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 20 | 21 | #include 22 | 23 | #if ! HAVE_INLINE 24 | # define static_inline 25 | #endif 26 | #include "xalloc.h" 27 | #undef static_inline 28 | 29 | #include 30 | #include 31 | 32 | #ifndef SIZE_MAX 33 | # define SIZE_MAX ((size_t) -1) 34 | #endif 35 | 36 | /* 1 if calloc is known to be compatible with GNU calloc. This 37 | matters if we are not also using the calloc module, which defines 38 | HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ 39 | #if defined HAVE_CALLOC || defined __GLIBC__ 40 | enum { HAVE_GNU_CALLOC = 1 }; 41 | #else 42 | enum { HAVE_GNU_CALLOC = 0 }; 43 | #endif 44 | 45 | /* Allocate N bytes of memory dynamically, with error checking. */ 46 | 47 | void * 48 | xmalloc (size_t n) 49 | { 50 | void *p = malloc (n); 51 | if (!p && n != 0) 52 | xalloc_die (); 53 | return p; 54 | } 55 | 56 | /* Change the size of an allocated block of memory P to N bytes, 57 | with error checking. */ 58 | 59 | void * 60 | xrealloc (void *p, size_t n) 61 | { 62 | p = realloc (p, n); 63 | if (!p && n != 0) 64 | xalloc_die (); 65 | return p; 66 | } 67 | 68 | /* If P is null, allocate a block of at least *PN bytes; otherwise, 69 | reallocate P so that it contains more than *PN bytes. *PN must be 70 | nonzero unless P is null. Set *PN to the new block's size, and 71 | return the pointer to the new block. *PN is never set to zero, and 72 | the returned pointer is never null. */ 73 | 74 | void * 75 | x2realloc (void *p, size_t *pn) 76 | { 77 | return x2nrealloc (p, pn, 1); 78 | } 79 | 80 | /* Allocate S bytes of zeroed memory dynamically, with error checking. 81 | There's no need for xnzalloc (N, S), since it would be equivalent 82 | to xcalloc (N, S). */ 83 | 84 | void * 85 | xzalloc (size_t s) 86 | { 87 | return memset (xmalloc (s), 0, s); 88 | } 89 | 90 | /* Allocate zeroed memory for N elements of S bytes, with error 91 | checking. S must be nonzero. */ 92 | 93 | void * 94 | xcalloc (size_t n, size_t s) 95 | { 96 | void *p; 97 | /* Test for overflow, since some calloc implementations don't have 98 | proper overflow checks. But omit overflow and size-zero tests if 99 | HAVE_GNU_CALLOC, since GNU calloc catches overflow and never 100 | returns NULL if successful. */ 101 | if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) 102 | || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) 103 | xalloc_die (); 104 | return p; 105 | } 106 | 107 | /* Clone an object P of size S, with error checking. There's no need 108 | for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any 109 | need for an arithmetic overflow check. */ 110 | 111 | void * 112 | xmemdup (void const *p, size_t s) 113 | { 114 | return memcpy (xmalloc (s), p, s); 115 | } 116 | 117 | /* Clone STRING. */ 118 | 119 | char * 120 | xstrdup (char const *string) 121 | { 122 | return xmemdup (string, strlen (string) + 1); 123 | } 124 | -------------------------------------------------------------------------------- /everything-updatedb/lib.c: -------------------------------------------------------------------------------- 1 | /* Common functions. 2 | 3 | Copyright (C) 2005, 2007 Red Hat, Inc. All rights reserved. 4 | This copyrighted material is made available to anyone wishing to use, modify, 5 | copy, or redistribute it subject to the terms and conditions of the GNU General 6 | Public License v.2. 7 | 8 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 14 | Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | 16 | Author: Miloslav Trmac */ 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "error.h" 31 | #include "obstack.h" 32 | #include "safe-read.h" 33 | #include "verify.h" 34 | #include "xalloc.h" 35 | 36 | #include "db.h" 37 | #include "lib.h" 38 | 39 | /* Convert VAL to big endian */ 40 | uint64_t 41 | htonll (uint64_t val) 42 | { 43 | uint32_t low, high; 44 | uint64_t ret; 45 | verify (sizeof (ret) == sizeof (high) + sizeof (low)); 46 | 47 | low = htonl ((uint32_t)val); 48 | high = htonl (val >> 32); 49 | memcpy (&ret, &high, sizeof (high)); 50 | memcpy ((unsigned char *)&ret + sizeof (high), &low, sizeof (low)); 51 | return ret; 52 | } 53 | 54 | /* Convert VAL from big endian */ 55 | uint64_t 56 | ntohll (uint64_t val) 57 | { 58 | uint32_t low, high; 59 | verify (sizeof (high) + sizeof (low) == sizeof (val)); 60 | 61 | memcpy (&high, &val, sizeof (high)); 62 | memcpy (&low, (unsigned char *)&val + sizeof (high), sizeof (low)); 63 | return (uint64_t)ntohl (high) << 32 | ntohl (low); 64 | } 65 | 66 | /* A mapping table for dir_path_cmp: '\0' < '/' < anything else */ 67 | static unsigned char dir_path_cmp_table[UCHAR_MAX + 1]; 68 | 69 | /* Initialize dir_path_cmp_table */ 70 | void 71 | dir_path_cmp_init (void) 72 | { 73 | size_t i; 74 | unsigned char val; 75 | 76 | dir_path_cmp_table[0] = 0; 77 | dir_path_cmp_table['/'] = 1; 78 | val = (unsigned char)2; 79 | for (i = 1; i < ARRAY_SIZE (dir_path_cmp_table); i++) 80 | { 81 | if (i != '/') 82 | { 83 | dir_path_cmp_table[i] = val; 84 | val++; 85 | } 86 | } 87 | assert (val == 0); 88 | } 89 | 90 | /* Compare two path names using the database directory order. This is not 91 | exactly strcmp () order: "a" < "a.b", so "a/z" < "a.b". */ 92 | int 93 | dir_path_cmp (const char *a, const char *b) 94 | { 95 | while (*a == *b && *a != 0) 96 | { 97 | a++; 98 | b++; 99 | } 100 | { 101 | verify (sizeof (int) > sizeof (unsigned char)); /* To rule out overflow */ 102 | } 103 | return ((int)dir_path_cmp_table[(unsigned char)*a] 104 | - (int)dir_path_cmp_table[(unsigned char)*b]); 105 | } 106 | 107 | /* Used by obstack code */ 108 | struct _obstack_chunk * 109 | obstack_chunk_alloc (long size) 110 | { 111 | return xmalloc (size); 112 | } 113 | 114 | /* String list utilities */ 115 | 116 | /* Append STRING to LIST */ 117 | void 118 | string_list_append (struct string_list *list, char *string) 119 | { 120 | if (list->allocated == list->len) 121 | list->entries = x2nrealloc (list->entries, &list->allocated, 122 | sizeof (*list->entries)); 123 | list->entries[list->len] = string; 124 | list->len++; 125 | } 126 | 127 | /* Compare two string pointers using dir_path_cmp () */ 128 | static int 129 | cmp_dir_path_pointers (const void *xa, const void *xb) 130 | { 131 | char *const *a, *const *b; 132 | 133 | a = xa; 134 | b = xb; 135 | return dir_path_cmp (*a, *b); 136 | } 137 | 138 | /* Sort LIST using dir_path_cmp () */ 139 | void 140 | string_list_dir_path_sort (struct string_list *list) 141 | { 142 | qsort (list->entries, list->len, sizeof (*list->entries), 143 | cmp_dir_path_pointers); 144 | } 145 | 146 | /* Is PATH included in LIST? Update *IDX to move within LIST. 147 | 148 | LIST is assumed to be sorted using dir_path_cmp (), successive calls to this 149 | function are assumed to use PATH values increasing in dir_path_cmp (). */ 150 | bool 151 | string_list_contains_dir_path (const struct string_list *list, size_t *idx, 152 | const char *path) 153 | { 154 | int cmp; 155 | 156 | cmp = 0; 157 | while (*idx < list->len 158 | && (cmp = dir_path_cmp (list->entries[*idx], path)) < 0) 159 | (*idx)++; 160 | if (*idx < list->len && cmp == 0) 161 | { 162 | (*idx)++; 163 | return true; 164 | } 165 | return false; 166 | } 167 | 168 | /* Reading of existing databases */ 169 | 170 | /* Open FILENAME (already open as FD), as DB, report error on failure if not 171 | QUIET. Store database header to *HEADER; return 0 if OK, -1 on error. 172 | If OK, takes ownership of FD: it will be closed by db_close (). 173 | 174 | FILENAME must stay valid until db_close (). */ 175 | int 176 | db_open (struct db *db, struct db_header *header, int fd, const char *filename, 177 | bool quiet) 178 | { 179 | static const uint8_t magic[] = DB_MAGIC; 180 | 181 | db->fd = fd; 182 | db->filename = filename; 183 | db->read_bytes = 0; 184 | db->quiet = quiet; 185 | db->err = 0; 186 | db->buf_pos = db->buffer; 187 | db->buf_end = db->buffer; 188 | if (db_read (db, header, sizeof (*header)) != 0) 189 | { 190 | db_report_error (db); 191 | goto err; 192 | } 193 | { 194 | verify (sizeof (magic) == sizeof (header->magic)); 195 | } 196 | if (memcmp (header->magic, magic, sizeof (magic)) != 0) 197 | { 198 | if (quiet == 0) 199 | error (0, 0, _("`%s' does not seem to be a mlocate database"), 200 | filename); 201 | goto err; 202 | } 203 | if (header->version != DB_VERSION_0) 204 | { 205 | if (quiet == 0) 206 | error (0, 0, _("`%s' has unknown version %u"), filename, 207 | (unsigned)header->version); 208 | goto err; 209 | } 210 | if (header->check_visibility != 0 && header->check_visibility != 1) 211 | { 212 | if (quiet == 0) 213 | error (0, 0, _("`%s' has unknown visibility flag %u"), filename, 214 | (unsigned)header->check_visibility); 215 | goto err; 216 | } 217 | return 0; 218 | 219 | err: 220 | return -1; 221 | } 222 | 223 | /* Close DB */ 224 | void 225 | db_close (struct db *db) 226 | { 227 | close (db->fd); 228 | } 229 | 230 | /* Refill empty DB->buffer; 231 | return number of bytes in buffer if OK, 0 on error or EOF */ 232 | static size_t 233 | db_refill (struct db *db) 234 | { 235 | size_t size; 236 | 237 | { 238 | verify (sizeof (db->buffer) < SAFE_READ_ERROR); 239 | } 240 | size = safe_read (db->fd, db->buffer, sizeof (db->buffer)); 241 | switch (size) 242 | { 243 | case 0: 244 | db->err = 0; 245 | return 0; 246 | 247 | case SAFE_READ_ERROR: 248 | db->err = errno; 249 | return 0; 250 | 251 | default: 252 | db->buf_pos = db->buffer; 253 | db->buf_end = db->buffer + size; 254 | db->read_bytes += size; 255 | return size; 256 | } 257 | } 258 | 259 | /* Report read error or unexpected EOF on DB if not DB->quiet */ 260 | void 261 | db_report_error (const struct db *db) 262 | { 263 | if (db->quiet != false) 264 | return; 265 | if (db->err != 0) 266 | error (0, db->err, _("I/O error reading `%s'"), db->filename); 267 | else 268 | error (0, 0, _("unexpected EOF reading `%s'"), db->filename); 269 | } 270 | 271 | /* Read SIZE (!= 0) bytes from DB to BUF; 272 | return 0 if OK, -1 on error */ 273 | int 274 | db_read (struct db *db, void *buf, size_t size) 275 | { 276 | assert (size != 0); 277 | do 278 | { 279 | size_t run; 280 | 281 | run = db->buf_end - db->buf_pos; 282 | if (run == 0) 283 | { 284 | run = db_refill (db); 285 | if (run == 0) 286 | return -1; 287 | } 288 | if (run > size) 289 | run = size; 290 | buf = mempcpy (buf, db->buf_pos, run); 291 | db->buf_pos += run; 292 | size -= run; 293 | } 294 | while (size != 0); 295 | return 0; 296 | } 297 | 298 | /* Read a NUL-terminated string from DB to current object in OBSTACK (without 299 | the terminating NUL), report error on failure if not DB->quiet. 300 | return 0 if OK, or -1 on I/O error. */ 301 | int 302 | db_read_name (struct db *db, struct obstack *h) 303 | { 304 | for (;;) 305 | { 306 | size_t run; 307 | char *nul; 308 | 309 | run = db->buf_end - db->buf_pos; 310 | if (run == 0) 311 | { 312 | run = db_refill (db); 313 | if (run == 0) 314 | goto err; 315 | } 316 | nul = memchr (db->buf_pos, 0, run); 317 | if (nul != NULL) 318 | { 319 | obstack_grow (h, db->buf_pos, nul - db->buf_pos); 320 | db->buf_pos = nul + 1; 321 | break; 322 | } 323 | obstack_grow (h, db->buf_pos, run); 324 | db->buf_pos = db->buf_end; 325 | } 326 | return 0; 327 | 328 | err: 329 | db_report_error (db); 330 | return -1; 331 | } 332 | 333 | /* Skip SIZE bytes in DB, report error on failure if not DB->quiet; 334 | return 0 if OK, -1 on error */ 335 | int 336 | db_skip (struct db *db, off_t size) 337 | { 338 | bool use_lseek; 339 | 340 | use_lseek = true; 341 | for (;;) 342 | { 343 | size_t run; 344 | 345 | run = db->buf_end - db->buf_pos; 346 | { 347 | /* To make sure the (ssize_t) cast below is safe. */ 348 | verify (sizeof (db->buffer) <= SSIZE_MAX); 349 | } 350 | if ((ssize_t)run > size) 351 | run = size; 352 | db->buf_pos += run; 353 | size -= run; 354 | if (size == 0) 355 | break; 356 | if (use_lseek != false) 357 | { 358 | if (lseek (db->fd, size, SEEK_CUR) != -1) 359 | break; 360 | if (errno != ESPIPE) 361 | { 362 | if (db->quiet == false) 363 | error (0, errno, _("I/O error seeking in `%s'"), db->filename); 364 | goto err; 365 | } 366 | use_lseek = false; 367 | } 368 | if (db_refill (db) == 0) 369 | { 370 | db_report_error (db); 371 | goto err; 372 | } 373 | } 374 | return 0; 375 | 376 | err: 377 | return -1; 378 | } 379 | 380 | /* Return number of bytes read from DB so far */ 381 | off_t 382 | db_bytes_read (const struct db *db) 383 | { 384 | return db->read_bytes - (db->buf_end - db->buf_pos); 385 | } 386 | -------------------------------------------------------------------------------- /everything-updatedb/lib.h: -------------------------------------------------------------------------------- 1 | /* Common functions. 2 | 3 | Copyright (C) 2005, 2007 Red Hat, Inc. All rights reserved. 4 | This copyrighted material is made available to anyone wishing to use, modify, 5 | copy, or redistribute it subject to the terms and conditions of the GNU General 6 | Public License v.2. 7 | 8 | This program is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 14 | Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | 16 | Author: Miloslav Trmac */ 17 | 18 | #ifndef LIB_H__ 19 | #define LIB_H__ 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "gettext.h" 29 | #include "obstack.h" 30 | 31 | #include "db.h" 32 | 33 | #ifdef __GNUC__ 34 | #define attribute__(X) __attribute__ (X) 35 | #else 36 | #define attribute__(X) 37 | #endif 38 | 39 | #define _(X) gettext(X) 40 | 41 | /* Number of entries in ARRAY */ 42 | #define ARRAY_SIZE(array) (sizeof (array) / sizeof (*array)) 43 | 44 | /* Convert VAL to big endian */ 45 | extern uint64_t htonll (uint64_t val); 46 | 47 | /* Convert VAL from big endian */ 48 | extern uint64_t ntohll (uint64_t val); 49 | 50 | /* Initialize dir_path_cmp_table */ 51 | extern void dir_path_cmp_init (void); 52 | 53 | /* Compare two path names using the database directory order. This is not 54 | exactly strcmp () order: "a" < "a.b", so "a/z" < "a.b". */ 55 | extern int dir_path_cmp (const char *a, const char *b); 56 | 57 | /* Functions used by obstack code */ 58 | extern struct _obstack_chunk *obstack_chunk_alloc (long size); 59 | 60 | #define obstack_chunk_free free 61 | 62 | /* The obstack code is too portable to be perfect :(. So we need some 63 | better substitutes to avoid 32-bit overflows. */ 64 | #define OBSTACK_OBJECT_SIZE(H) \ 65 | (size_t)((char *)obstack_next_free (H) - (char *)obstack_base (H)) 66 | 67 | /* To avoid obstack integer overflows, limit large obstack allocations to this 68 | value. */ 69 | enum { OBSTACK_SIZE_MAX = 1024 * 1024 }; 70 | 71 | /* A list of strings */ 72 | struct string_list 73 | { 74 | char **entries; 75 | size_t len; /* Number of valid entries */ 76 | /* Number of allocated entries, usually invalid after the list is "finished" 77 | and ENTRIES are reallocated to the exact size. */ 78 | size_t allocated; 79 | }; 80 | 81 | /* Append STRING to LIST */ 82 | extern void string_list_append (struct string_list *list, char *string); 83 | 84 | /* Sort LIST using dir_path_cmp () */ 85 | extern void string_list_dir_path_sort (struct string_list *list); 86 | 87 | /* Is PATH included in LIST? Update *IDX to move within LIST. 88 | 89 | LIST is assumed to be sorted using dir_path_cmp (), successive calls to this 90 | function are assumed to use PATH values increasing in dir_path_cmp (). */ 91 | extern bool string_list_contains_dir_path (const struct string_list *list, 92 | size_t *idx, const char *path); 93 | 94 | /* An open database */ 95 | struct db 96 | { 97 | int fd; 98 | const char *filename; 99 | off_t read_bytes; /* Total bytes read */ 100 | bool quiet; /* Don't report read errors */ 101 | int err; /* errno on last read error or 0 */ 102 | char *buf_pos, *buf_end; 103 | char buffer[BUFSIZ]; 104 | }; 105 | 106 | /* Open FILENAME (already open as FD), as DB, set DB's quiet flag to QUIET. 107 | Store database header to *HEADER; 108 | return 0 if OK, -1 on error. 109 | 110 | Takes ownership of FD: it will be closed by db_close () or before return 111 | from this function if it fails. 112 | 113 | FILENAME must stay valid until db_close (). */ 114 | extern int db_open (struct db *db, struct db_header *header, int fd, 115 | const char *filename, bool quiet); 116 | 117 | /* Close DB */ 118 | extern void db_close (struct db *db); 119 | 120 | /* Report read error or unexpected EOF on DB if not DB->quiet */ 121 | extern void db_report_error (const struct db *db); 122 | 123 | /* Read SIZE (!= 0) bytes from DB to BUF; 124 | return 0 if OK, -1 on error */ 125 | extern int db_read (struct db *db, void *buf, size_t size); 126 | 127 | /* Read a NUL-terminated string from DB to current object in OBSTACK (without 128 | the terminating NUL), report error on failure if not DB->quiet. 129 | return 0 if OK, or -1 on I/O error. */ 130 | extern int db_read_name (struct db *db, struct obstack *h); 131 | 132 | /* Skip SIZE bytes in DB, report error on failure if not DB->quiet; 133 | return 0 if OK, -1 on error */ 134 | extern int db_skip (struct db *db, off_t size); 135 | 136 | /* Return number of bytes read from DB so far */ 137 | extern off_t db_bytes_read (const struct db *db); 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /everything/EverythingForLinux.pro: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Automatically generated by qmake (2.01a) ?? 1? 15 16:02:17 2016 3 | ###################################################################### 4 | 5 | QT += core gui sql 6 | 7 | TEMPLATE = app 8 | TARGET = EverythingForLinux 9 | DEPENDPATH += . . 10 | INCLUDEPATH += . 11 | 12 | # Input 13 | HEADERS += mainwindow.h \ 14 | csqlquerymodel.h \ 15 | ctableview.h \ 16 | sudodialog.h \ 17 | updatedbsdialog.h \ 18 | taskmanager.h 19 | SOURCES += main.cpp mainwindow.cpp \ 20 | csqlquerymodel.cpp \ 21 | ctableview.cpp \ 22 | sudodialog.cpp \ 23 | updatedbsdialog.cpp \ 24 | taskmanager.cpp 25 | 26 | RESOURCES += \ 27 | res.qrc 28 | 29 | FORMS += \ 30 | sudodialog.ui \ 31 | updatedbsdialog.ui 32 | -------------------------------------------------------------------------------- /everything/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile for building: EverythingForLinux 3 | # Generated by qmake (2.01a) (Qt 4.8.6) on: ?? 5? 29 16:46:53 2016 4 | # Project: EverythingForLinux.pro 5 | # Template: app 6 | # Command: /usr/bin/qmake-qt4 -o Makefile EverythingForLinux.pro 7 | ############################################################################# 8 | 9 | ####### Compiler, tools and options 10 | 11 | CC = gcc 12 | CXX = g++ 13 | DEFINES = -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED 14 | CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) 15 | CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) 16 | INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtSql -I/usr/include/qt4 -I. -I. -I. 17 | LINK = g++ 18 | LFLAGS = -Wl,-O1 19 | LIBS = $(SUBLIBS) -L/usr/lib/i386-linux-gnu -lQtSql -lQtGui -lQtCore -lpthread 20 | AR = ar cqs 21 | RANLIB = 22 | QMAKE = /usr/bin/qmake-qt4 23 | TAR = tar -cf 24 | COMPRESS = gzip -9f 25 | COPY = cp -f 26 | SED = sed 27 | COPY_FILE = $(COPY) 28 | COPY_DIR = $(COPY) -r 29 | STRIP = strip 30 | INSTALL_FILE = install -m 644 -p 31 | INSTALL_DIR = $(COPY_DIR) 32 | INSTALL_PROGRAM = install -m 755 -p 33 | DEL_FILE = rm -f 34 | SYMLINK = ln -f -s 35 | DEL_DIR = rmdir 36 | MOVE = mv -f 37 | CHK_DIR_EXISTS= test -d 38 | MKDIR = mkdir -p 39 | 40 | ####### Output directory 41 | 42 | OBJECTS_DIR = ./ 43 | 44 | ####### Files 45 | 46 | SOURCES = main.cpp \ 47 | mainwindow.cpp \ 48 | csqlquerymodel.cpp \ 49 | ctableview.cpp \ 50 | sudodialog.cpp \ 51 | updatedbsdialog.cpp \ 52 | taskmanager.cpp moc_mainwindow.cpp \ 53 | moc_csqlquerymodel.cpp \ 54 | moc_ctableview.cpp \ 55 | moc_sudodialog.cpp \ 56 | moc_updatedbsdialog.cpp \ 57 | moc_taskmanager.cpp \ 58 | qrc_res.cpp 59 | OBJECTS = main.o \ 60 | mainwindow.o \ 61 | csqlquerymodel.o \ 62 | ctableview.o \ 63 | sudodialog.o \ 64 | updatedbsdialog.o \ 65 | taskmanager.o \ 66 | moc_mainwindow.o \ 67 | moc_csqlquerymodel.o \ 68 | moc_ctableview.o \ 69 | moc_sudodialog.o \ 70 | moc_updatedbsdialog.o \ 71 | moc_taskmanager.o \ 72 | qrc_res.o 73 | DIST = /usr/share/qt4/mkspecs/common/unix.conf \ 74 | /usr/share/qt4/mkspecs/common/linux.conf \ 75 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 76 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 77 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 78 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 79 | /usr/share/qt4/mkspecs/qconfig.pri \ 80 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 81 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 82 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 83 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 84 | /usr/share/qt4/mkspecs/features/release.prf \ 85 | /usr/share/qt4/mkspecs/features/default_post.prf \ 86 | /usr/share/qt4/mkspecs/features/shared.prf \ 87 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 88 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 89 | /usr/share/qt4/mkspecs/features/qt.prf \ 90 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 91 | /usr/share/qt4/mkspecs/features/moc.prf \ 92 | /usr/share/qt4/mkspecs/features/resources.prf \ 93 | /usr/share/qt4/mkspecs/features/uic.prf \ 94 | /usr/share/qt4/mkspecs/features/yacc.prf \ 95 | /usr/share/qt4/mkspecs/features/lex.prf \ 96 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 97 | EverythingForLinux.pro 98 | QMAKE_TARGET = EverythingForLinux 99 | DESTDIR = 100 | TARGET = EverythingForLinux 101 | 102 | first: all 103 | ####### Implicit rules 104 | 105 | .SUFFIXES: .o .c .cpp .cc .cxx .C 106 | 107 | .cpp.o: 108 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 109 | 110 | .cc.o: 111 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 112 | 113 | .cxx.o: 114 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 115 | 116 | .C.o: 117 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 118 | 119 | .c.o: 120 | $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" 121 | 122 | ####### Build rules 123 | 124 | all: Makefile $(TARGET) 125 | 126 | $(TARGET): ui_sudodialog.h ui_updatedbsdialog.h $(OBJECTS) 127 | $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) 128 | 129 | Makefile: EverythingForLinux.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ 130 | /usr/share/qt4/mkspecs/common/linux.conf \ 131 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 132 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 133 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 134 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 135 | /usr/share/qt4/mkspecs/qconfig.pri \ 136 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 137 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 138 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 139 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 140 | /usr/share/qt4/mkspecs/features/release.prf \ 141 | /usr/share/qt4/mkspecs/features/default_post.prf \ 142 | /usr/share/qt4/mkspecs/features/shared.prf \ 143 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 144 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 145 | /usr/share/qt4/mkspecs/features/qt.prf \ 146 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 147 | /usr/share/qt4/mkspecs/features/moc.prf \ 148 | /usr/share/qt4/mkspecs/features/resources.prf \ 149 | /usr/share/qt4/mkspecs/features/uic.prf \ 150 | /usr/share/qt4/mkspecs/features/yacc.prf \ 151 | /usr/share/qt4/mkspecs/features/lex.prf \ 152 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 153 | /usr/lib/i386-linux-gnu/libQtSql.prl \ 154 | /usr/lib/i386-linux-gnu/libQtGui.prl \ 155 | /usr/lib/i386-linux-gnu/libQtCore.prl 156 | $(QMAKE) -o Makefile EverythingForLinux.pro 157 | /usr/share/qt4/mkspecs/common/unix.conf: 158 | /usr/share/qt4/mkspecs/common/linux.conf: 159 | /usr/share/qt4/mkspecs/common/gcc-base.conf: 160 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf: 161 | /usr/share/qt4/mkspecs/common/g++-base.conf: 162 | /usr/share/qt4/mkspecs/common/g++-unix.conf: 163 | /usr/share/qt4/mkspecs/qconfig.pri: 164 | /usr/share/qt4/mkspecs/features/qt_functions.prf: 165 | /usr/share/qt4/mkspecs/features/qt_config.prf: 166 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf: 167 | /usr/share/qt4/mkspecs/features/default_pre.prf: 168 | /usr/share/qt4/mkspecs/features/release.prf: 169 | /usr/share/qt4/mkspecs/features/default_post.prf: 170 | /usr/share/qt4/mkspecs/features/shared.prf: 171 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: 172 | /usr/share/qt4/mkspecs/features/warn_on.prf: 173 | /usr/share/qt4/mkspecs/features/qt.prf: 174 | /usr/share/qt4/mkspecs/features/unix/thread.prf: 175 | /usr/share/qt4/mkspecs/features/moc.prf: 176 | /usr/share/qt4/mkspecs/features/resources.prf: 177 | /usr/share/qt4/mkspecs/features/uic.prf: 178 | /usr/share/qt4/mkspecs/features/yacc.prf: 179 | /usr/share/qt4/mkspecs/features/lex.prf: 180 | /usr/share/qt4/mkspecs/features/include_source_dir.prf: 181 | /usr/lib/i386-linux-gnu/libQtSql.prl: 182 | /usr/lib/i386-linux-gnu/libQtGui.prl: 183 | /usr/lib/i386-linux-gnu/libQtCore.prl: 184 | qmake: FORCE 185 | @$(QMAKE) -o Makefile EverythingForLinux.pro 186 | 187 | dist: 188 | @$(CHK_DIR_EXISTS) .tmp/EverythingForLinux1.0.0 || $(MKDIR) .tmp/EverythingForLinux1.0.0 189 | $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/EverythingForLinux1.0.0/ && $(COPY_FILE) --parents mainwindow.h csqlquerymodel.h ctableview.h sudodialog.h updatedbsdialog.h taskmanager.h .tmp/EverythingForLinux1.0.0/ && $(COPY_FILE) --parents res.qrc .tmp/EverythingForLinux1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp csqlquerymodel.cpp ctableview.cpp sudodialog.cpp updatedbsdialog.cpp taskmanager.cpp .tmp/EverythingForLinux1.0.0/ && $(COPY_FILE) --parents sudodialog.ui updatedbsdialog.ui .tmp/EverythingForLinux1.0.0/ && (cd `dirname .tmp/EverythingForLinux1.0.0` && $(TAR) EverythingForLinux1.0.0.tar EverythingForLinux1.0.0 && $(COMPRESS) EverythingForLinux1.0.0.tar) && $(MOVE) `dirname .tmp/EverythingForLinux1.0.0`/EverythingForLinux1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/EverythingForLinux1.0.0 190 | 191 | 192 | clean:compiler_clean 193 | -$(DEL_FILE) $(OBJECTS) 194 | -$(DEL_FILE) *~ core *.core 195 | 196 | 197 | ####### Sub-libraries 198 | 199 | distclean: clean 200 | -$(DEL_FILE) $(TARGET) 201 | -$(DEL_FILE) Makefile 202 | 203 | 204 | check: first 205 | 206 | mocclean: compiler_moc_header_clean compiler_moc_source_clean 207 | 208 | mocables: compiler_moc_header_make_all compiler_moc_source_make_all 209 | 210 | compiler_moc_header_make_all: moc_mainwindow.cpp moc_csqlquerymodel.cpp moc_ctableview.cpp moc_sudodialog.cpp moc_updatedbsdialog.cpp moc_taskmanager.cpp 211 | compiler_moc_header_clean: 212 | -$(DEL_FILE) moc_mainwindow.cpp moc_csqlquerymodel.cpp moc_ctableview.cpp moc_sudodialog.cpp moc_updatedbsdialog.cpp moc_taskmanager.cpp 213 | moc_mainwindow.cpp: csqlquerymodel.h \ 214 | ctableview.h \ 215 | mainwindow.h 216 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp 217 | 218 | moc_csqlquerymodel.cpp: csqlquerymodel.h 219 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) csqlquerymodel.h -o moc_csqlquerymodel.cpp 220 | 221 | moc_ctableview.cpp: ctableview.h 222 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) ctableview.h -o moc_ctableview.cpp 223 | 224 | moc_sudodialog.cpp: ui_sudodialog.h \ 225 | sudodialog.h 226 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) sudodialog.h -o moc_sudodialog.cpp 227 | 228 | moc_updatedbsdialog.cpp: ui_updatedbsdialog.h \ 229 | taskmanager.h \ 230 | updatedbsdialog.h 231 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) updatedbsdialog.h -o moc_updatedbsdialog.cpp 232 | 233 | moc_taskmanager.cpp: taskmanager.h 234 | /usr/lib/i386-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) taskmanager.h -o moc_taskmanager.cpp 235 | 236 | compiler_rcc_make_all: qrc_res.cpp 237 | compiler_rcc_clean: 238 | -$(DEL_FILE) qrc_res.cpp 239 | qrc_res.cpp: res.qrc \ 240 | windowIcon.png 241 | /usr/lib/i386-linux-gnu/qt4/bin/rcc -name res res.qrc -o qrc_res.cpp 242 | 243 | compiler_image_collection_make_all: qmake_image_collection.cpp 244 | compiler_image_collection_clean: 245 | -$(DEL_FILE) qmake_image_collection.cpp 246 | compiler_moc_source_make_all: 247 | compiler_moc_source_clean: 248 | compiler_uic_make_all: ui_sudodialog.h ui_updatedbsdialog.h 249 | compiler_uic_clean: 250 | -$(DEL_FILE) ui_sudodialog.h ui_updatedbsdialog.h 251 | ui_sudodialog.h: sudodialog.ui 252 | /usr/lib/i386-linux-gnu/qt4/bin/uic sudodialog.ui -o ui_sudodialog.h 253 | 254 | ui_updatedbsdialog.h: updatedbsdialog.ui 255 | /usr/lib/i386-linux-gnu/qt4/bin/uic updatedbsdialog.ui -o ui_updatedbsdialog.h 256 | 257 | compiler_yacc_decl_make_all: 258 | compiler_yacc_decl_clean: 259 | compiler_yacc_impl_make_all: 260 | compiler_yacc_impl_clean: 261 | compiler_lex_make_all: 262 | compiler_lex_clean: 263 | compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean 264 | 265 | ####### Compile 266 | 267 | main.o: main.cpp mainwindow.h \ 268 | csqlquerymodel.h \ 269 | ctableview.h \ 270 | updatedbsdialog.h \ 271 | ui_updatedbsdialog.h \ 272 | taskmanager.h 273 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp 274 | 275 | mainwindow.o: mainwindow.cpp mainwindow.h \ 276 | csqlquerymodel.h \ 277 | ctableview.h \ 278 | sudodialog.h \ 279 | ui_sudodialog.h 280 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp 281 | 282 | csqlquerymodel.o: csqlquerymodel.cpp csqlquerymodel.h 283 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o csqlquerymodel.o csqlquerymodel.cpp 284 | 285 | ctableview.o: ctableview.cpp ctableview.h \ 286 | csqlquerymodel.h 287 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o ctableview.o ctableview.cpp 288 | 289 | sudodialog.o: sudodialog.cpp sudodialog.h \ 290 | ui_sudodialog.h 291 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o sudodialog.o sudodialog.cpp 292 | 293 | updatedbsdialog.o: updatedbsdialog.cpp updatedbsdialog.h \ 294 | ui_updatedbsdialog.h \ 295 | taskmanager.h \ 296 | sudodialog.h \ 297 | ui_sudodialog.h 298 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o updatedbsdialog.o updatedbsdialog.cpp 299 | 300 | taskmanager.o: taskmanager.cpp taskmanager.h 301 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o taskmanager.o taskmanager.cpp 302 | 303 | moc_mainwindow.o: moc_mainwindow.cpp 304 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp 305 | 306 | moc_csqlquerymodel.o: moc_csqlquerymodel.cpp 307 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_csqlquerymodel.o moc_csqlquerymodel.cpp 308 | 309 | moc_ctableview.o: moc_ctableview.cpp 310 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ctableview.o moc_ctableview.cpp 311 | 312 | moc_sudodialog.o: moc_sudodialog.cpp 313 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_sudodialog.o moc_sudodialog.cpp 314 | 315 | moc_updatedbsdialog.o: moc_updatedbsdialog.cpp 316 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_updatedbsdialog.o moc_updatedbsdialog.cpp 317 | 318 | moc_taskmanager.o: moc_taskmanager.cpp 319 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_taskmanager.o moc_taskmanager.cpp 320 | 321 | qrc_res.o: qrc_res.cpp 322 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_res.o qrc_res.cpp 323 | 324 | ####### Install 325 | 326 | install: FORCE 327 | 328 | uninstall: FORCE 329 | 330 | FORCE: 331 | 332 | -------------------------------------------------------------------------------- /everything/csqlquerymodel.cpp: -------------------------------------------------------------------------------- 1 | #include "csqlquerymodel.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | CSqlQueryModel::CSqlQueryModel(QObject *parent) : 12 | QSqlQueryModel(parent) 13 | { 14 | m_hoverRow = -1; 15 | } 16 | 17 | void CSqlQueryModel::setHoverRow(int row) 18 | { 19 | m_hoverRow = row; 20 | } 21 | 22 | QVariant CSqlQueryModel::data (const QModelIndex & item, int role) const 23 | { 24 | /* Set background color of hover row RGBA(51,153,255,100)*/ 25 | if (item.row() == m_hoverRow && Qt::BackgroundRole == role) 26 | { 27 | return QBrush(QColor(51, 153, 255, 100)); 28 | } 29 | 30 | static time_t s_mtime; 31 | static size_t s_size; 32 | 33 | /* Set 'size' column alignment right|vcenter, other left|vcenter*/ 34 | if (item.column() == COLUMN_SIZE) 35 | { 36 | if (role == Qt::TextAlignmentRole) 37 | { 38 | return QVariant(Qt::AlignRight | Qt::AlignVCenter); 39 | } 40 | else if (role == Qt::DisplayRole) 41 | { 42 | return sizeValue(s_size); 43 | } 44 | } 45 | 46 | if (item.column() == COLUMN_MTIME && role == Qt::DisplayRole) 47 | { 48 | return timeValue(s_mtime); 49 | } 50 | 51 | /* icon in REC_NAME section */ 52 | if (role == Qt::DecorationRole && item.column() == COLUMN_NAME) 53 | { 54 | struct stat fileStat; 55 | const QString strFilePath = record(item.row()).value("path").toString() + "/" + record(item.row()).value("name").toString(); 56 | stat(strFilePath.toLatin1().data(), &fileStat); 57 | 58 | s_mtime = fileStat.st_mtime; 59 | s_size = fileStat.st_size; 60 | 61 | QFileInfo fileInfo(strFilePath); 62 | return m_iconProvider.icon(fileInfo); 63 | } 64 | 65 | return QSqlQueryModel::data(item, role); 66 | } 67 | 68 | QVariant CSqlQueryModel::timeValue(const time_t timep) const 69 | { 70 | struct tm *stTime = NULL; 71 | stTime = localtime(&timep); 72 | return QString("%1/%2/%3 %4:%5") 73 | .arg(stTime->tm_year+1900) 74 | .arg(stTime->tm_mon+1) 75 | .arg(stTime->tm_mday) 76 | .arg(stTime->tm_hour) 77 | .arg(stTime->tm_min); 78 | } 79 | 80 | QVariant CSqlQueryModel::sizeValue(const size_t size) const 81 | { 82 | return QString("%1 KB").arg(size/1024.0, 0, 'f', 2); 83 | } 84 | 85 | void CSqlQueryModel::setQuery ( const QString & query, const QSqlDatabase & db) 86 | { 87 | qDebug() << query; 88 | QSqlQueryModel::setQuery(query, db); 89 | insertColumn(3); 90 | } 91 | -------------------------------------------------------------------------------- /everything/csqlquerymodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CSQLQUERYMODEL_H 2 | #define CSQLQUERYMODEL_H 3 | 4 | #include 5 | #include 6 | 7 | enum { 8 | COLUMN_NAME, 9 | COLUMN_PATH, 10 | COLUMN_SIZE, 11 | COLUMN_MTIME, 12 | COLUMN_NUM 13 | }; 14 | 15 | class CSqlQueryModel : public QSqlQueryModel 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit CSqlQueryModel(QObject *parent = 0); 20 | QVariant data ( const QModelIndex & item, int role = Qt::DisplayRole ) const ; 21 | void setQuery ( const QString & query, const QSqlDatabase & db = QSqlDatabase()); 22 | 23 | private: 24 | QVariant sizeValue(const size_t size) const; 25 | QVariant timeValue(const time_t timep) const; 26 | 27 | signals: 28 | 29 | public slots: 30 | void setHoverRow(int row); 31 | 32 | private: 33 | int m_hoverRow; 34 | QFileIconProvider m_iconProvider; 35 | }; 36 | 37 | #endif // CSQLQUERYMODEL_H 38 | -------------------------------------------------------------------------------- /everything/ctableview.cpp: -------------------------------------------------------------------------------- 1 | #include "ctableview.h" 2 | #include "csqlquerymodel.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class CLineDelegate : public QStyledItemDelegate 12 | { 13 | public: 14 | CLineDelegate(QObject* parent = 0); 15 | protected: 16 | void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; 17 | private: 18 | QPen pen; 19 | }; 20 | 21 | CLineDelegate::CLineDelegate(QObject *parent) : 22 | QStyledItemDelegate(parent) 23 | { 24 | QColor gridColor(0,0,0,50); 25 | pen = QPen(gridColor, 0, Qt::SolidLine); 26 | } 27 | void CLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,const QModelIndex& index)const 28 | { 29 | QStyledItemDelegate::paint(painter, option, index); 30 | QPen oldPen = painter->pen(); 31 | painter->setPen(pen); 32 | 33 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); 34 | painter->setPen(oldPen); 35 | } 36 | 37 | CTableView::CTableView(QWidget *parent) : 38 | QTableView(parent) 39 | { 40 | m_hoverRow = -1; 41 | setupView(); 42 | 43 | setMouseTracking(true); 44 | connect(this, SIGNAL(entered(const QModelIndex & )), this, SLOT(updateRow(const QModelIndex & ))); 45 | } 46 | 47 | void CTableView::setupView() 48 | { 49 | setFocusPolicy(Qt::NoFocus); 50 | setSelectionBehavior(QAbstractItemView::SelectRows); 51 | setSelectionMode(QAbstractItemView::SingleSelection); 52 | setTextElideMode(Qt::ElideMiddle); 53 | setWordWrap(false); 54 | setShowGrid(false); 55 | setItemDelegate(new CLineDelegate); 56 | 57 | 58 | 59 | verticalHeader()->setHidden(true); 60 | 61 | 62 | horizontalHeader()->setClickable(false); 63 | } 64 | 65 | 66 | void CTableView::updateRow(const QModelIndex &item) 67 | { 68 | int row = item.row(); 69 | if (row == m_hoverRow) 70 | return; 71 | 72 | emit hoverRowChanged(row); 73 | int columnCount = model()->columnCount(); 74 | for (int i = columnCount - 1; i >= 0; i--) 75 | { 76 | update(model()->index(m_hoverRow, i)); 77 | update(model()->index(row, i)); 78 | } 79 | m_hoverRow = row; 80 | } 81 | 82 | void CTableView::leaveEvent(QEvent *event) 83 | { 84 | emit hoverRowChanged(-1); 85 | if (model() != NULL) 86 | { 87 | int columnCount = model()->columnCount(); 88 | for (int i = columnCount - 1; i >= 0; i--) 89 | { 90 | update(model()->index(m_hoverRow, i)); 91 | } 92 | } 93 | m_hoverRow = -1; 94 | } 95 | -------------------------------------------------------------------------------- /everything/ctableview.h: -------------------------------------------------------------------------------- 1 | #ifndef CTABLEVIEW_H 2 | #define CTABLEVIEW_H 3 | 4 | #include 5 | 6 | class CTableView : public QTableView 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit CTableView(QWidget *parent = 0); 11 | 12 | signals: 13 | void hoverRowChanged(int row); 14 | 15 | public slots: 16 | void updateRow(const QModelIndex & index); 17 | 18 | protected: 19 | void leaveEvent(QEvent *event); 20 | 21 | 22 | private: 23 | void setupView(); 24 | 25 | private: 26 | int m_hoverRow; 27 | }; 28 | 29 | #endif // CTABLEVIEW_H 30 | -------------------------------------------------------------------------------- /everything/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | UpdateDbsDialog updateDbsDialog(&w); 11 | QObject::connect(&updateDbsDialog, SIGNAL(databaseUpdated()), &w, SLOT(reloadModel())); 12 | updateDbsDialog.exec(); 13 | return a.exec(); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /everything/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | MainWindow::MainWindow(QWidget *parent) : 9 | QMainWindow(parent), m_sourceModel() 10 | { 11 | setupUi(); 12 | setWindowIcon(QIcon(QPixmap("://windowIcon.png"))); 13 | m_sourceModel = new CSqlQueryModel; 14 | m_sqlQuery = new QSqlQuery; 15 | m_db = QSqlDatabase::addDatabase("QSQLITE"); 16 | m_db.setDatabaseName(strDbName); 17 | if (connectDb()) 18 | { 19 | loadSettings(1); 20 | initTable(); 21 | } 22 | } 23 | 24 | MainWindow::~MainWindow() 25 | { 26 | delete m_sqlQuery; 27 | } 28 | 29 | void MainWindow::setupUi() 30 | { 31 | resize(698, 351); 32 | centralWidget = new QWidget(this); 33 | 34 | verticalLayout = new QVBoxLayout(centralWidget); 35 | verticalLayout->setSpacing(3); 36 | verticalLayout->setContentsMargins(1, 1, 1, 1); 37 | 38 | horizontalLayout = new QHBoxLayout(); 39 | horizontalLayout->setSpacing(3); 40 | 41 | keywordEdit = new QLineEdit(centralWidget); 42 | keywordEdit->setObjectName(QString::fromUtf8("keywordEdit")); 43 | 44 | horizontalLayout->addWidget(keywordEdit); 45 | 46 | verticalLayout->addLayout(horizontalLayout); 47 | 48 | tableView = new CTableView(centralWidget); 49 | tableView->setObjectName(QString::fromUtf8("tableView")); 50 | 51 | verticalLayout->addWidget(tableView); 52 | 53 | setCentralWidget(centralWidget); 54 | 55 | menuBar = new QMenuBar(this); 56 | menuBar->setGeometry(QRect(0, 0, 700, 25)); 57 | setMenuBar(menuBar); 58 | 59 | statusBar = new QStatusBar(this); 60 | setStatusBar(statusBar); 61 | 62 | /* set title and texts */ 63 | retranslateUi(); 64 | 65 | /* connect slots by OBJECT name */ 66 | QMetaObject::connectSlotsByName(this); 67 | } 68 | 69 | void MainWindow::retranslateUi() 70 | { 71 | setWindowTitle(QApplication::translate("MainWindow", "Everything", 0, QApplication::UnicodeUTF8)); 72 | } 73 | 74 | bool MainWindow::reConnectDb() 75 | { 76 | if (!m_db.isOpen()) 77 | { 78 | m_db.close(); 79 | } 80 | 81 | connectDb(); 82 | 83 | return true; 84 | } 85 | 86 | bool MainWindow::connectDb() 87 | { 88 | if (!m_db.open()) 89 | { 90 | QMessageBox::warning(0, "Connect Database Error", m_db.lastError().text()); 91 | return false; 92 | } 93 | return true; 94 | } 95 | 96 | bool MainWindow::initTable() 97 | { 98 | m_sourceModel->setQuery(strSelectSQL + strOrderByNm); 99 | m_sourceModel->setHeaderData(0, Qt::Horizontal, "Name"); 100 | m_sourceModel->setHeaderData(1, Qt::Horizontal, "Path"); 101 | m_sourceModel->setHeaderData(2, Qt::Horizontal, "Size"); 102 | m_sourceModel->setHeaderData(3, Qt::Horizontal, "Data Modified"); 103 | 104 | tableView->setModel(m_sourceModel); 105 | tableView->setColumnWidth(0, 208); 106 | tableView->setColumnWidth(1, 270); 107 | tableView->setColumnWidth(2, 70); 108 | tableView->setColumnWidth(3, 130); 109 | tableView->setStyleSheet("QTableView{border-style: none}" 110 | "QTableView::item:selected{background: rgb(51,153,255)}"); 111 | 112 | connect(tableView, SIGNAL(hoverRowChanged(int)), m_sourceModel, SLOT(setHoverRow(int))); 113 | 114 | /* create right button menu */ 115 | tableView->setContextMenuPolicy(Qt::CustomContextMenu); 116 | connect(tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); 117 | 118 | return true; 119 | } 120 | 121 | void MainWindow::on_tableView_doubleClicked(const QModelIndex & index) 122 | { 123 | m_showContextRow = index.row(); 124 | openFile(); 125 | } 126 | 127 | void MainWindow::openFile() 128 | { 129 | QString cmd = "xdg-open " + tableView->model()->index(m_showContextRow, 1).data().toString() + "/" 130 | + tableView->model()->index(m_showContextRow, 0).data().toString(); 131 | if (system(cmd.toLocal8Bit().data()) != 0) 132 | { 133 | QMessageBox::warning(this, "Error opening", "No application is registered as handling this file"); 134 | } 135 | } 136 | 137 | void MainWindow::openFilePath() 138 | { 139 | QString cmd = "xdg-open " + tableView->model()->index(m_showContextRow, 1).data().toString(); 140 | system(cmd.toLocal8Bit().data()); 141 | } 142 | 143 | void MainWindow::copyFullPath() 144 | { 145 | QClipboard *board = QApplication::clipboard(); 146 | QString path = tableView->model()->index(m_showContextRow, 1).data().toString(); 147 | QString name = tableView->model()->index(m_showContextRow, 0).data().toString(); 148 | if (path == "/") 149 | { 150 | board->setText(path + name); 151 | } 152 | else 153 | { 154 | board->setText(path + "/" + name); 155 | } 156 | } 157 | 158 | void MainWindow::showContextMenu(const QPoint &pos) 159 | { 160 | if (tableView->indexAt(pos).row() == -1) 161 | { 162 | return; 163 | } 164 | 165 | m_showContextRow = tableView->indexAt(pos).row(); 166 | 167 | QMenu menu(this); 168 | QAction *open = menu.addAction("Open"); 169 | QAction *openPath = menu.addAction("Open Path"); 170 | QAction *copyFullPath = menu.addAction("Copy Full Name to Clipboard"); 171 | 172 | connect(open, SIGNAL(triggered()), this, SLOT(openFile())); 173 | connect(openPath, SIGNAL(triggered()), this, SLOT(openFilePath())); 174 | connect(copyFullPath, SIGNAL(triggered()), this, SLOT(copyFullPath())); 175 | menu.exec(QCursor::pos()); 176 | } 177 | 178 | bool MainWindow::loadSettings(bool loadDefault) 179 | { 180 | if (loadDefault) 181 | { 182 | m_enableMatchCase = false; 183 | m_enableRegex = false; 184 | } 185 | else 186 | { 187 | //load settings from ini file 188 | } 189 | } 190 | 191 | void MainWindow::setTitle(const QString& text) 192 | { 193 | if (text.isEmpty()) 194 | { 195 | setWindowTitle("Everything"); 196 | } 197 | else 198 | { 199 | setWindowTitle(text + " - Everything"); 200 | } 201 | } 202 | 203 | void MainWindow::setFilter(const QString& text) 204 | { 205 | // m_sourceModel->setQuery(strSelectSQL+" WHERE name LIKE '%" + text + "%' ORDER BY name"); 206 | // m_proxyModel->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive)); 207 | if (text.contains('*')) 208 | { 209 | if (m_enableMatchCase) 210 | { 211 | m_sourceModel->setQuery(strSelectSQL + strWhereGlob.arg(text) + strOrderByNm); 212 | } 213 | else 214 | { 215 | QString keyword = text; 216 | m_sourceModel->setQuery(strSelectSQL + strWhereLike.arg(keyword.replace('*', '%')) + strOrderByNm); 217 | } 218 | } 219 | else 220 | { 221 | if (m_enableMatchCase) 222 | { 223 | m_sourceModel->setQuery(strSelectSQL + strWhereGlobWildcard.arg(text) + strOrderByNm); 224 | } 225 | else 226 | { 227 | m_sourceModel->setQuery(strSelectSQL + strWhereLikeWildcard.arg(text) + strOrderByNm); 228 | } 229 | } 230 | } 231 | 232 | void MainWindow::on_keywordEdit_textChanged() 233 | { 234 | setTitle(keywordEdit->text()); 235 | setFilter(keywordEdit->text()); 236 | } 237 | 238 | void MainWindow::reloadModel() 239 | { 240 | qDebug() << "reloadModel"; 241 | reConnectDb(); 242 | loadSettings(1); 243 | initTable(); 244 | 245 | m_sourceModel->setQuery(strSelectSQL + strOrderByNm); 246 | } 247 | -------------------------------------------------------------------------------- /everything/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "csqlquerymodel.h" 14 | #include "ctableview.h" 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | const QString strSelectSQL = "SELECT name, path, type FROM everything"; 22 | const QString strWhereGlobWildcard = " WHERE name GLOB '*%1*'"; /* match case */ 23 | const QString strWhereLikeWildcard = " WHERE name LIKE '%%1%'"; 24 | const QString strWhereGlob = " WHERE name GLOB '%1'"; /* match case */ 25 | const QString strWhereLike = " WHERE name LIKE '%1'"; 26 | const QString strOrderByNm = " ORDER BY name"; 27 | const QString strCountSelectSQL = "SELECT COUNT(*) FROM everything"; 28 | const QString strDbName = "/var/lib/everything/everything.db"; 29 | 30 | class MainWindow : public QMainWindow 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | explicit MainWindow(QWidget *parent = 0); 36 | ~MainWindow(); 37 | 38 | signals: 39 | 40 | public slots: 41 | void on_keywordEdit_textChanged(); 42 | void reloadModel(); 43 | void on_tableView_doubleClicked(const QModelIndex & index); 44 | void showContextMenu(const QPoint &pos); 45 | void openFile(); 46 | void openFilePath(); 47 | void copyFullPath(); 48 | 49 | private: 50 | void setupUi(); 51 | void retranslateUi(); 52 | bool initTable(); 53 | bool connectDb(); 54 | bool reConnectDb(); 55 | bool loadSettings(bool loadDefault = false); 56 | void setFilter(const QString& text); 57 | void setTitle(const QString& text); 58 | 59 | public: 60 | CSqlQueryModel *m_sourceModel; 61 | QSqlQuery *m_sqlQuery; 62 | QSqlDatabase m_db; 63 | 64 | /* settings */ 65 | bool m_enableMatchCase; 66 | bool m_enableRegex; 67 | 68 | /* GUI widgets */ 69 | QWidget *centralWidget; 70 | QVBoxLayout *verticalLayout; 71 | QHBoxLayout *horizontalLayout; 72 | QLineEdit *keywordEdit; 73 | CTableView *tableView; 74 | QMenuBar *menuBar; 75 | QStatusBar *statusBar; 76 | 77 | private: 78 | int m_showContextRow; 79 | }; 80 | 81 | #endif // MAINWINDOW_H 82 | 83 | -------------------------------------------------------------------------------- /everything/res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | windowIcon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /everything/sudodialog.cpp: -------------------------------------------------------------------------------- 1 | #include "sudodialog.h" 2 | #include "ui_sudodialog.h" 3 | #include 4 | 5 | SudoDialog::SudoDialog(QWidget *parent) : 6 | QDialog(parent, Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint), m_attemptTimes(0) 7 | { 8 | setupUi(this); 9 | incorrectLabel->hide(); 10 | okBtn->setEnabled(false); 11 | } 12 | 13 | SudoDialog::~SudoDialog() 14 | { 15 | 16 | } 17 | 18 | QString SudoDialog::getPassward() 19 | { 20 | return m_passward; 21 | } 22 | 23 | void SudoDialog::setPassward(const QString &text) 24 | { 25 | if (!text.isEmpty()) 26 | { 27 | m_passward = text; 28 | } 29 | } 30 | 31 | #include 32 | QString SudoDialog::getValidPassword(QWidget *parent) 33 | { 34 | SudoDialog dlg(parent); 35 | if (dlg.exec() == QDialog::Accepted) 36 | { 37 | return dlg.getPassward(); 38 | } 39 | return QString(); 40 | } 41 | 42 | 43 | bool SudoDialog::attemptLogin() 44 | { 45 | QProcess proc; 46 | proc.start("sudo -k"); 47 | proc.waitForFinished(1000); 48 | 49 | QString commd = "sudo"; 50 | QStringList arguments; 51 | arguments << "-S" << "true"; 52 | proc.start(commd, arguments); 53 | QByteArray passward = pwdLineEdit->text().toUtf8(); 54 | proc.write(passward + "\n"); 55 | if (!proc.waitForFinished(1000)) 56 | { 57 | qDebug() << proc.errorString(); 58 | proc.kill(); 59 | proc.waitForFinished(1000); 60 | return false; 61 | } 62 | return true; 63 | } 64 | 65 | void SudoDialog::on_cancelBtn_clicked() 66 | { 67 | reject(); 68 | } 69 | 70 | void SudoDialog::on_okBtn_clicked() 71 | { 72 | if (attemptLogin()) 73 | { 74 | setPassward(pwdLineEdit->text()); 75 | accept(); 76 | } 77 | else 78 | { 79 | if (++m_attemptTimes >= 3) 80 | { 81 | reject(); 82 | } 83 | incorrectLabel->show(); 84 | pwdLineEdit->clear(); 85 | } 86 | } 87 | 88 | void SudoDialog::on_pwdLineEdit_textChanged(const QString &text) 89 | { 90 | if (!text.isEmpty()) 91 | { 92 | okBtn->setEnabled(true); 93 | } 94 | else 95 | { 96 | okBtn->setEnabled(false); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /everything/sudodialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SUDODIALOG_H 2 | #define SUDODIALOG_H 3 | 4 | #include 5 | #include "ui_sudodialog.h" 6 | 7 | class SudoDialog : public QDialog, public Ui_SudoDialog 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | explicit SudoDialog(QWidget *parent = 0); 13 | ~SudoDialog(); 14 | QString getPassward(); 15 | 16 | static QString getValidPassword(QWidget *parent); 17 | 18 | private: 19 | void setPassward(const QString &text); 20 | bool attemptLogin(); 21 | 22 | private slots: 23 | void on_cancelBtn_clicked(); 24 | void on_okBtn_clicked(); 25 | void on_pwdLineEdit_textChanged(const QString &text); 26 | 27 | 28 | private: 29 | QString m_passward; 30 | int m_attemptTimes; 31 | 32 | }; 33 | 34 | #endif // SUDODIALOG_H 35 | -------------------------------------------------------------------------------- /everything/sudodialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SudoDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 300 10 | 210 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | font: 14px 18 | 19 | 20 | 21 | 22 | 23 | font: bold 16px; 24 | 25 | 26 | Enter your password to perform administrative tasks. 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | The application 'Everything' let you modify essential parts of your system. 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | font: bold; 47 | 48 | 49 | Incorrect password... try again. 50 | 51 | 52 | Qt::AlignCenter 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | Passward : 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | QLineEdit::Password 72 | 73 | 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 0 84 | 85 | 86 | 87 | 88 | Qt::Horizontal 89 | 90 | 91 | 92 | 40 93 | 20 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | Cancel 102 | 103 | 104 | 105 | 106 | 107 | 108 | OK 109 | 110 | 111 | true 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /everything/taskmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "taskmanager.h" 2 | #include 3 | 4 | TaskManager* TaskManager::m_taskManager; 5 | 6 | TaskManager::TaskManager(QObject *parent) : 7 | QThread(parent), m_pProc(NULL) 8 | { 9 | } 10 | 11 | TaskManager::~TaskManager() 12 | { 13 | if (m_pProc != NULL) 14 | { 15 | delete m_pProc; 16 | } 17 | } 18 | 19 | bool TaskManager::sudoRunProcess(const QString &program, const QStringList &arguments) 20 | { 21 | qDebug() << "sudo run process: " << m_passward << program << arguments; 22 | QStringList args; 23 | args << "-S" << program << arguments; 24 | m_pProc->start("sudo", args); 25 | m_pProc->write(m_passward.toUtf8() + "\n"); 26 | if (!m_pProc->waitForFinished(1000 * 60)) 27 | { 28 | qDebug() << m_pProc->errorString(); 29 | m_pProc->terminate(); 30 | m_pProc->waitForFinished(1000 * 5); 31 | return false; 32 | } 33 | 34 | if (m_pProc->exitCode() != 0) 35 | { 36 | return false; 37 | } 38 | 39 | return true; 40 | } 41 | 42 | void TaskManager::run() 43 | { 44 | qDebug() << "taskmanager is running"; 45 | 46 | if (!m_passward.isEmpty()) 47 | { 48 | m_pProc = new QProcess(); 49 | 50 | /* task No1 : run updatedb */ 51 | emit taskFinished(TASKID_UPDATE_LOCATEDB, sudoRunProcess("updatedb")); 52 | 53 | /* task No2 : run everything-updatedb */ 54 | emit taskFinished(TASKID_UPDATE_SEARCHDB, sudoRunProcess("./everything-updatedb")); 55 | 56 | } 57 | exit(); 58 | } 59 | void TaskManager::setPassward(const QString &passward) 60 | { 61 | m_passward = passward; 62 | } 63 | 64 | TaskManager* TaskManager::getTaskManager(QObject *parent) 65 | { 66 | if (m_taskManager == NULL) 67 | { 68 | m_taskManager = new TaskManager(parent); 69 | } 70 | 71 | return m_taskManager; 72 | } 73 | -------------------------------------------------------------------------------- /everything/taskmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef TASKMANAGER_H 2 | #define TASKMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | enum 8 | { 9 | TASKID_UPDATE_LOCATEDB = 1, 10 | TASKID_UPDATE_SEARCHDB, 11 | }; 12 | 13 | class TaskManager : public QThread 14 | { 15 | Q_OBJECT 16 | public: 17 | ~TaskManager(); 18 | void run(); 19 | void setPassward(const QString &passward); 20 | 21 | static TaskManager *getTaskManager(QObject *parent = 0); 22 | static TaskManager *m_taskManager; 23 | 24 | private: 25 | explicit TaskManager(QObject *parent = 0); 26 | bool sudoRunProcess(const QString &program, const QStringList &arguments = QStringList()); 27 | 28 | signals: 29 | void taskFinished(int taskid, bool success); 30 | 31 | public slots: 32 | 33 | private: 34 | QProcess* m_pProc; 35 | QString m_passward; 36 | }; 37 | 38 | 39 | 40 | #endif // TASKMANAGER_H 41 | -------------------------------------------------------------------------------- /everything/updatedbsdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "updatedbsdialog.h" 2 | #include "ui_updatedbsdialog.h" 3 | #include "sudodialog.h" 4 | #include 5 | #include 6 | #include 7 | 8 | UpdateDbsDialog::UpdateDbsDialog(QWidget *parent) : 9 | QDialog(parent, Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint), m_passwardValid(false), m_pTaskMgr(NULL) 10 | { 11 | setupUi(this); 12 | updateStat->hide(); 13 | locateDbRes->hide(); 14 | searchDbRes->hide(); 15 | } 16 | 17 | UpdateDbsDialog::~UpdateDbsDialog() 18 | { 19 | if (m_pTaskMgr != NULL) 20 | { 21 | delete m_pTaskMgr; 22 | } 23 | } 24 | 25 | void UpdateDbsDialog::on_cancelBtn_clicked() 26 | { 27 | close(); 28 | } 29 | 30 | 31 | void UpdateDbsDialog::on_unlockBtn_clicked() 32 | { 33 | const QString password = SudoDialog::getValidPassword(this); 34 | if (password.isEmpty()) 35 | { 36 | updateStat->setText("Authentication failed."); 37 | updateStat->show(); 38 | return; 39 | } 40 | 41 | updateStat->setText("Updating database..."); 42 | updateStat->show(); 43 | cancelBtn->setDisabled(true); 44 | unlockBtn->setDisabled(true); 45 | 46 | m_pTaskMgr = TaskManager::getTaskManager(this); 47 | QObject::connect(m_pTaskMgr, SIGNAL(taskFinished(int,bool)), this, SLOT(taskFinish(int,bool))); 48 | m_pTaskMgr->setPassward(password); 49 | m_pTaskMgr->start(); 50 | } 51 | 52 | void UpdateDbsDialog::onProcFinished(int exitCode, QProcess::ExitStatus exitStatus) 53 | { 54 | qDebug() << "on finish: " << exitCode << exitStatus; 55 | } 56 | 57 | void UpdateDbsDialog::taskFinish(int taskid, bool success) 58 | { 59 | switch(taskid) 60 | { 61 | case TASKID_UPDATE_LOCATEDB: 62 | if (success) 63 | { 64 | locateDbRes->setText("Locate database updated successfully."); 65 | } 66 | else 67 | { 68 | locateDbRes->setText("Locate database updated failed."); 69 | } 70 | locateDbRes->show(); 71 | break; 72 | 73 | case TASKID_UPDATE_SEARCHDB: 74 | if (success) 75 | { 76 | searchDbRes->setText("Search database updated successfully."); 77 | } 78 | else 79 | { 80 | searchDbRes->setText("Search database updated failed."); 81 | } 82 | searchDbRes->show(); 83 | unlockBtn->hide(); 84 | cancelBtn->setText("close"); 85 | cancelBtn->setEnabled(true); 86 | updateStat->setDisabled(true); 87 | emit databaseUpdated(); 88 | break; 89 | 90 | default: 91 | break; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /everything/updatedbsdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef UPDATEDBSDIALOG_H 2 | #define UPDATEDBSDIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "taskmanager.h" 8 | 9 | class UpdateDbsDialog : public QDialog, public Ui_UpdateDbsDialog 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit UpdateDbsDialog(QWidget *parent = 0); 15 | ~UpdateDbsDialog(); 16 | 17 | signals: 18 | void databaseUpdated(); 19 | 20 | private slots: 21 | void on_cancelBtn_clicked(); 22 | void on_unlockBtn_clicked(); 23 | void onProcFinished(int exitCode, QProcess::ExitStatus exitStatus); 24 | void taskFinish(int taskid, bool success); 25 | 26 | private: 27 | 28 | 29 | private: 30 | bool m_passwardValid; 31 | TaskManager* m_pTaskMgr; 32 | }; 33 | 34 | #endif // UPDATEDBSDIALOG_H 35 | -------------------------------------------------------------------------------- /everything/updatedbsdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | UpdateDbsDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 480 10 | 201 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | font: 14px 18 | 19 | 20 | 21 | 22 | 23 | 0 24 | 25 | 26 | 27 | 28 | 29 | 0 30 | 30 31 | 32 | 33 | 34 | font: normal bold 16px; 35 | 36 | 37 | Update locate database and search database 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 46 | 30 47 | 48 | 49 | 50 | To provide accurate results, the locate database and the search database needs to be refreshed. 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | 59 | 60 | This requires sudo (admin) rights. 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 0 70 | 71 | 72 | 73 | 74 | status 75 | 76 | 77 | 78 | 79 | 80 | 81 | locatedbresult 82 | 83 | 84 | 85 | 86 | 87 | 88 | searchdbresult 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | Qt::Horizontal 100 | 101 | 102 | 103 | 40 104 | 20 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Cancel 113 | 114 | 115 | 116 | 117 | 118 | 119 | Unlock 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /everything/windowIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mention0/EverythingForLinux/f5add0754808dc88d4adc30d5bb4fe1aad5b70dd/everything/windowIcon.png --------------------------------------------------------------------------------